Skip to content

Commit

Permalink
added version, timeout and promisc flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dreadl0ck committed Sep 17, 2020
1 parent cd34339 commit 3d71567
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This package exports the following API:
Live Capture from interface, outputs CSV with configurable separator or JSON:

```go
func ReadInterface(iface string, out io.Writer, separator string, ja3s bool, asJSON bool, snaplen int) {
func ReadInterface(iface string, out io.Writer, separator string, ja3s bool, asJSON bool, snaplen int, promisc bool, timeout time.Duration) {
```
Files:
Expand Down
15 changes: 13 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"os"
"time"

"github.com/dreadl0ck/ja3"
)
Expand All @@ -32,17 +33,27 @@ var (
flagInterface = flag.String("iface", "", "specify network interface to read packets from")
flagJa3S = flag.Bool("ja3s", true, "include ja3 server hashes (ja3s)")
flagOnlyJa3S = flag.Bool("ja3s-only", false, "dump ja3s only")
flagSnaplen = flag.Int("snaplen", 1514, "default snaplen for ethernet frames")
flagSnaplen = flag.Int("snaplen", 1514, "default snap length for ethernet frames")
flagPromisc = flag.Bool("promisc", true, "capture in promiscuous mode (requires root)")
flagTimeout = flag.Duration("timeout", 30*time.Second, "timeout for opening the network interface handle")
flagVersion = flag.Bool("version", false, "display version and exit")
)

const version = "v1.0.2"

func main() {

flag.Parse()

if *flagVersion {
fmt.Println(version)
os.Exit(0)
}

ja3.Debug = *flagDebug

if *flagInterface != "" {
ja3.ReadInterface(*flagInterface, os.Stdout, *flagSeparator, *flagJa3S, *flagJSON, *flagSnaplen)
ja3.ReadInterface(*flagInterface, os.Stdout, *flagSeparator, *flagJa3S, *flagJSON, *flagSnaplen, *flagPromisc, *flagTimeout)
return
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module github.com/dreadl0ck/ja3

require (
github.com/dreadl0ck/gopacket v1.1.16-0.20200114112008-4960f4b77557 // indirect
github.com/dreadl0ck/tlsx v1.0.1-google-gopacket
github.com/google/gopacket v1.1.18
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
github.com/dreadl0ck/gopacket v1.1.16-0.20200114112008-4960f4b77557 h1:m/rxJiRUgei39RuIVBMPipyRGokYe534vBfuARBcLnU=
github.com/dreadl0ck/gopacket v1.1.16-0.20200114112008-4960f4b77557/go.mod h1:d7HEeaw/pAxzNTUprrDDpb7RxPsWA9i3NFp1ZfBNl50=
github.com/dreadl0ck/tlsx v1.0.1-dreadl0ck-gopacket h1:FOqjFi//FT2SslC28SqsqkiSYzXIqcrjqYOOufSA6TU=
github.com/dreadl0ck/tlsx v1.0.1-dreadl0ck-gopacket/go.mod h1:sBTlLV54BjDf/gqC3YuFIhs5DKslo/BW/M/mHkCkNM4=
github.com/dreadl0ck/tlsx v1.0.1-google-gopacket h1:/P3y+CGRiCQbW0nZU2jWkEwKfXLkpEgHNhbbqlnrTTM=
github.com/dreadl0ck/tlsx v1.0.1-google-gopacket/go.mod h1:amAb73WEEgPHWniMfwro6UpN6St3e5ypgq2tXM89IOo=
github.com/google/gopacket v1.1.17 h1:rMrlX2ZY2UbvT+sdz3+6J+pp2z+msCq9MxTU6ymxbBY=
Expand Down
9 changes: 5 additions & 4 deletions live.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"strings"
"time"

"github.com/google/gopacket"
"github.com/google/gopacket/layers"
Expand All @@ -15,9 +16,9 @@ import (
// ReadInterface reads packets from the named interface
// if asJSON is true the results will be dumped as newline separated JSON objects
// otherwise CSV will be printed to the supplied io.Writer.
func ReadInterface(iface string, out io.Writer, separator string, ja3s bool, asJSON bool, snaplen int) {
func ReadInterface(iface string, out io.Writer, separator string, ja3s bool, asJSON bool, snaplen int, promisc bool, timeout time.Duration) {

h, err := pcap.OpenLive(iface, int32(snaplen), true, -1)
h, err := pcap.OpenLive(iface, int32(snaplen), promisc, timeout)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -47,8 +48,8 @@ func ReadInterface(iface string, out io.Writer, separator string, ja3s bool, asJ

var (
// create gopacket
p = gopacket.NewPacket(data, layers.LinkTypeEthernet, gopacket.Lazy)
bare = BarePacket(p)
p = gopacket.NewPacket(data, layers.LinkTypeEthernet, gopacket.Lazy)
bare = BarePacket(p)
isServer bool
)

Expand Down

0 comments on commit 3d71567

Please sign in to comment.