Skip to content

Commit cc17dda

Browse files
Merge pull request #1 from shadowy-pycoder/oui
Oui package
2 parents f468b2e + 88afbbe commit cc17dda

29 files changed

+96360
-247
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
![mshark_new](https://github.com/user-attachments/assets/ee1b9526-dcae-4ff8-962d-315897e49ed0)
2+
23
# mShark - Mini [Wireshark](https://www.wireshark.org/) written in Go
34

45
[![Go Reference](https://pkg.go.dev/badge/github.com/shadowy-pycoder/mshark.svg)](https://pkg.go.dev/github.com/shadowy-pycoder/mshark)
@@ -8,7 +9,6 @@
89
![GitHub Release](https://img.shields.io/github/v/release/shadowy-pycoder/mshark)
910
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/shadowy-pycoder/mshark/total)
1011

11-
1212
## Installation
1313

1414
Download release from [Releases](https://github.com/shadowy-pycoder/mshark/releases) Page.
@@ -18,9 +18,11 @@ Or install using `go install` (requires Go 1.23+ but may work with older version
1818
```shell
1919
CGO_ENABLED=0 go install -ldflags "-s -w" -trimpath github.com/shadowy-pycoder/mshark/cmd/mshark@latest
2020
```
21+
2122
This will install the `mshark` binary to your `$GOPATH/bin` directory.
2223

23-
If you are getting a `Permission denied` error when running `mshark`, try running
24+
If you are getting a `Permission denied` error when running `mshark`, try running
25+
2426
```shell
2527
sudo setcap cap_net_raw+ep ~/go/bin/mshark
2628
```
@@ -30,24 +32,26 @@ sudo setcap cap_net_raw+ep ~/go/bin/mshark
3032
```shell
3133
mshark -h
3234

33-
______ __ __
34-
/ \ | \ | \
35-
______ ____ | $$$$$$\| $$____ ______ ______ | $$ __
35+
______ __ __
36+
/ \ | \ | \
37+
______ ____ | $$$$$$\| $$____ ______ ______ | $$ __
3638
| \ \ | $$___\$$| $$ \ | \ / \ | $$ / \
3739
| $$$$$$\$$$$\ \$$ \ | $$$$$$$\ \$$$$$$\| $$$$$$\| $$_/ $$
38-
| $$ | $$ | $$ _\$$$$$$\| $$ | $$ / $$| $$ \$$| $$ $$
39-
| $$ | $$ | $$| \__| $$| $$ | $$| $$$$$$$| $$ | $$$$$$\
40+
| $$ | $$ | $$ _\$$$$$$\| $$ | $$ / $$| $$ \$$| $$ $$
41+
| $$ | $$ | $$| \__| $$| $$ | $$| $$$$$$$| $$ | $$$$$$\
4042
| $$ | $$ | $$ \$$ $$| $$ | $$ \$$ $$| $$ | $$ \$$\
4143
\$$ \$$ \$$ \$$$$$$ \$$ \$$ \$$$$$$$ \$$ \$$ \$$
42-
43-
Packet Capture Tool by shadowy-pycoder
44+
45+
Packet Capture Tool by shadowy-pycoder
4446

4547
GitHub: https://github.com/shadowy-pycoder/mshark
4648

4749
Usage: mshark [OPTIONS]
4850
Options:
4951
-h Show this help message and exit.
5052
-D Display list of interfaces and exit.
53+
-b int
54+
The maximum size of packet queue. (default 8192)
5155
-c int
5256
The maximum number of packets to capture.
5357
-e string
@@ -62,13 +66,14 @@ Options:
6266
-t duration
6367
The maximum duration of the packet capture process. Example: 5s
6468
-v Display full packet info when capturing to stdout or txt.
65-
```
69+
```
6670

6771
### Example
6872

6973
```shell
7074
mshark -p -f=txt -f=stdout -f=pcapng -i eth0 -e="port 53"
7175
```
76+
7277
The above command will capture packets containing `port 53` (assumed to be DNS queries) from the `eth0` interface and write the captured data to `stdout`, `txt`, and file in `pcapng` format. Files are created in the current working directory.
7378

7479
Output:
@@ -79,20 +84,21 @@ Output:
7984
- Promiscuous Mode: true
8085
- Timeout: 0s
8186
- Number of Packets: 0
87+
- Packet Buffer Size: 8192
8288
- BPF Filter: "port 53"
8389
- Verbose: false
8490
```
91+
8592
![Screenshot from 2024-09-17 09-37-50](https://github.com/user-attachments/assets/44c233ee-85a4-43f2-8f65-1ef239362bab)
8693

8794
With `-v` flag enabled, you will see more detailed information:
8895

89-
9096
![Screenshot from 2024-09-17 09-56-20](https://github.com/user-attachments/assets/11539ea7-779e-4faf-8fce-2eea9ab653c7)
9197
![Screenshot from 2024-09-17 09-56-47](https://github.com/user-attachments/assets/26b6353d-d312-40c5-9917-3f2f7bb8abdc)
9298

9399
## Supported layers
94100

95-
- [Ethernet](https://en.wikipedia.org/wiki/Ethernet_frame)
101+
- [Ethernet](https://en.wikipedia.org/wiki/Ethernet_frame)
96102
- [IPv4](https://en.wikipedia.org/wiki/IPv4)
97103
- [IPv6](https://en.wikipedia.org/wiki/IPv6)
98104
- [ARP](https://en.wikipedia.org/wiki/Address_Resolution_Protocol)
@@ -107,7 +113,6 @@ With `-v` flag enabled, you will see more detailed information:
107113
- [SSH](https://en.wikipedia.org/wiki/Secure_Shell)
108114
- [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security)
109115

110-
111116
## Roadmap
112117

113118
- [x] Online packet capture to `stdout`, `txt`, `pcap` and `pcapng` files

arpspoof/arpspoof.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package arpspoof
2+
package arpspoof

cmd/mshark/cli.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ import (
1919
const app string = "mshark"
2020

2121
const usagePrefix string = `
22-
______ __ __
23-
/ \ | \ | \
24-
______ ____ | $$$$$$\| $$____ ______ ______ | $$ __
22+
______ __ __
23+
/ \ | \ | \
24+
______ ____ | $$$$$$\| $$____ ______ ______ | $$ __
2525
| \ \ | $$___\$$| $$ \ | \ / \ | $$ / \
2626
| $$$$$$\$$$$\ \$$ \ | $$$$$$$\ \$$$$$$\| $$$$$$\| $$_/ $$
27-
| $$ | $$ | $$ _\$$$$$$\| $$ | $$ / $$| $$ \$$| $$ $$
28-
| $$ | $$ | $$| \__| $$| $$ | $$| $$$$$$$| $$ | $$$$$$\
27+
| $$ | $$ | $$ _\$$$$$$\| $$ | $$ / $$| $$ \$$| $$ $$
28+
| $$ | $$ | $$| \__| $$| $$ | $$| $$$$$$$| $$ | $$$$$$\
2929
| $$ | $$ | $$ \$$ $$| $$ | $$ \$$ $$| $$ | $$ \$$\
3030
\$$ \$$ \$$ \$$$$$$ \$$ \$$ \$$$$$$$ \$$ \$$ \$$
31-
32-
Packet Capture Tool by shadowy-pycoder
31+
32+
Packet Capture Tool by shadowy-pycoder
3333
3434
GitHub: https://github.com/shadowy-pycoder/mshark
3535
@@ -79,7 +79,7 @@ func displayInterfaces() error {
7979

8080
func createFile(app, ext string) (*os.File, error) {
8181
path := fmt.Sprintf("./%s_%s.%s", app, time.Now().UTC().Format("20060102_150405"), ext)
82-
f, err := os.OpenFile(filepath.FromSlash(path), os.O_CREATE|os.O_WRONLY, 0644)
82+
f, err := os.OpenFile(filepath.FromSlash(path), os.O_CREATE|os.O_WRONLY, 0o644)
8383
if err != nil {
8484
return nil, fmt.Errorf("failed to open file: %v", err)
8585
}
@@ -92,12 +92,17 @@ func root(args []string) error {
9292
flags := flag.NewFlagSet(app, flag.ExitOnError)
9393
iface := flags.String("i", "any", "The name of the network interface. Example: eth0")
9494
snaplen := flags.Int("s", 0, "The maximum length of each packet snapshot. Defaults to 65535.")
95-
flags.BoolFunc("p", `Promiscuous mode. This setting is ignored for "any" interface. Defaults to false.`, func(flagValue string) error {
96-
conf.Promisc = true
97-
return nil
98-
})
95+
flags.BoolFunc(
96+
"p",
97+
`Promiscuous mode. This setting is ignored for "any" interface. Defaults to false.`,
98+
func(flagValue string) error {
99+
conf.Promisc = true
100+
return nil
101+
},
102+
)
99103
flags.DurationVar(&conf.Timeout, "t", 0, "The maximum duration of the packet capture process. Example: 5s")
100104
flags.IntVar(&conf.PacketCount, "c", 0, "The maximum number of packets to capture.")
105+
packetBuffer := flags.Int("b", 8192, "The maximum size of packet queue.")
101106
flags.StringVar(&conf.Expr, "e", "", `BPF filter expression. Example: "ip proto tcp".`)
102107
flags.BoolFunc("D", "Display list of interfaces and exit.", func(flagValue string) error {
103108
if err := displayInterfaces(); err != nil {
@@ -137,6 +142,11 @@ func root(args []string) error {
137142
}
138143
conf.Snaplen = *snaplen
139144

145+
if *packetBuffer <= 0 {
146+
*packetBuffer = 8192
147+
}
148+
conf.PacketBuffer = *packetBuffer
149+
140150
// creating writers and writing headers depending on a file extension
141151
var pw []ms.PacketWriter
142152
if len(exts) != 0 {
@@ -193,8 +203,5 @@ func root(args []string) error {
193203
}
194204
pw = append(pw, w)
195205
}
196-
if err := ms.OpenLive(&conf, pw...); err != nil {
197-
return err
198-
}
199-
return nil
206+
return ms.OpenLive(&conf, pw...)
200207
}

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
module github.com/shadowy-pycoder/mshark
22

3-
go 1.23.0
3+
go 1.24.1
44

55
require (
6+
github.com/magefile/mage v1.15.0
67
github.com/mdlayher/packet v1.1.2
78
github.com/packetcap/go-pcap v0.0.0-20240528124601-8c87ecf5dbc5
89
github.com/stretchr/testify v1.9.0
910
golang.org/x/net v0.28.0
11+
golang.org/x/text v0.27.0
1012
)
1113

1214
require (
1315
github.com/davecgh/go-spew v1.1.1 // indirect
1416
github.com/josharian/native v1.1.0 // indirect
1517
github.com/mdlayher/socket v0.4.1 // indirect
1618
github.com/pmezard/go-difflib v1.0.0 // indirect
17-
golang.org/x/sync v0.1.0 // indirect
19+
golang.org/x/sync v0.16.0 // indirect
1820
golang.org/x/sys v0.24.0 // indirect
1921
gopkg.in/yaml.v3 v3.0.1 // indirect
2022
)

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/gopacket/gopacket v1.2.0 h1:eXbzFad7f73P1n2EJHQlsKuvIMJjVXK5tXoSca78I
66
github.com/gopacket/gopacket v1.2.0/go.mod h1:BrAKEy5EOGQ76LSqh7DMAr7z0NNPdczWm2GxCG7+I8M=
77
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
88
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
9+
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
10+
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
911
github.com/mdlayher/packet v1.1.2 h1:3Up1NG6LZrsgDVn6X4L9Ge/iyRyxFEFD9o6Pr3Q1nQY=
1012
github.com/mdlayher/packet v1.1.2/go.mod h1:GEu1+n9sG5VtiRE4SydOmX5GTwyyYlteZiFU+x0kew4=
1113
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
@@ -18,10 +20,12 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
1820
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
1921
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
2022
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
21-
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
22-
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
23+
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
24+
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
2325
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
2426
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
27+
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
28+
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
2529
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2630
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2731
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)