Improve documentation and add warning when no gopath (#219)

* Improve documentation

* Add warning when no GOPATH set with default dictionaries
This commit is contained in:
Brendan Le Glaunec
2019-06-11 09:02:24 +02:00
committed by GitHub
parent 0f011a1797
commit 35b0cf26d9
3 changed files with 34 additions and 9 deletions
+6 -5
View File
@@ -206,12 +206,13 @@ Your image will be called `cameradar` and NOT `ullaakut/cameradar`.
#### Go build #### Go build
Make sure you installed the [dependencies](#dependencies), and that you have Go modules enabled (`GO111MODULE=on`) Make sure you installed the [dependencies](#dependencies), **and that you have Go modules enabled (`GO111MODULE=on`)**.
1. `go get github.com/ullaakut/cameradar` 1. `export GO111MODULE=on` (unless it's already on)
2. `cd $GOPATH/src/github.com/ullaakut/cameradar` 2. `go get github.com/ullaakut/cameradar`
3. `cd cameradar` 3. `cd $GOPATH/src/github.com/ullaakut/cameradar`
4. `go build` 4. `cd cmd/cameradar`
5. `go build`
The cameradar binary is now in the root of the directory. The cameradar binary is now in the root of the directory.
+12 -2
View File
@@ -7,9 +7,15 @@ import (
"time" "time"
"github.com/ullaakut/disgo" "github.com/ullaakut/disgo"
"github.com/ullaakut/disgo/style"
curl "github.com/ullaakut/go-curl" curl "github.com/ullaakut/go-curl"
) )
const (
defaultCredentialDictionaryPath = "<GOPATH>/src/github.com/ullaakut/cameradar/dictionaries/credentials.json"
defaultRouteDictionaryPath = "<GOPATH>/src/github.com/ullaakut/cameradar/dictionaries/routes"
)
// Scanner represents a cameradar scanner. It scans a network and // Scanner represents a cameradar scanner. It scans a network and
// attacks all streams found to get their RTSP credentials. // attacks all streams found to get their RTSP credentials.
type Scanner struct { type Scanner struct {
@@ -43,8 +49,8 @@ func New(options ...func(*Scanner)) (*Scanner, error) {
scanner := &Scanner{ scanner := &Scanner{
curl: &Curl{CURL: handle}, curl: &Curl{CURL: handle},
credentialDictionaryPath: "<GOPATH>/src/github.com/ullaakut/cameradar/dictionaries/credentials.json", credentialDictionaryPath: defaultCredentialDictionaryPath,
routeDictionaryPath: "<GOPATH>/src/github.com/ullaakut/cameradar/dictionaries/routes", routeDictionaryPath: defaultRouteDictionaryPath,
} }
for _, option := range options { for _, option := range options {
@@ -52,6 +58,10 @@ func New(options ...func(*Scanner)) (*Scanner, error) {
} }
gopath := os.Getenv("GOPATH") gopath := os.Getenv("GOPATH")
if gopath == "" && scanner.credentialDictionaryPath == defaultCredentialDictionaryPath && scanner.routeDictionaryPath == defaultRouteDictionaryPath {
disgo.Errorln(style.Failure("No $GOPATH was found.\nDictionaries may not be loaded properly, please set your $GOPATH to use the default dictionaries."))
}
scanner.credentialDictionaryPath = strings.Replace(scanner.credentialDictionaryPath, "<GOPATH>", gopath, 1) scanner.credentialDictionaryPath = strings.Replace(scanner.credentialDictionaryPath, "<GOPATH>", gopath, 1)
scanner.routeDictionaryPath = strings.Replace(scanner.routeDictionaryPath, "<GOPATH>", gopath, 1) scanner.routeDictionaryPath = strings.Replace(scanner.routeDictionaryPath, "<GOPATH>", gopath, 1)
+16 -2
View File
@@ -3,6 +3,7 @@ package cameradar
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"testing" "testing"
"time" "time"
@@ -75,23 +76,36 @@ func TestNew(t *testing.T) {
curlEasyFail: true, curlEasyFail: true,
expectedErr: true,
},
{
description: "gopath not set and default dicts",
customCredentials: defaultCredentialDictionaryPath,
customRoutes: defaultRouteDictionaryPath,
expectedErr: true, expectedErr: true,
}, },
} }
// Temporarily empty the gopath for testing purposes.
defer os.Setenv("GOPATH", os.Getenv("GOPATH"))
for i, test := range tests { for i, test := range tests {
t.Run(test.description, func(t *testing.T) { t.Run(test.description, func(t *testing.T) {
os.Setenv("GOPATH", "")
if test.loadTargetsFail { if test.loadTargetsFail {
test.targets = []string{generateTmpFileName(i, "targets")} test.targets = []string{generateTmpFileName(i, "targets")}
ioutil.WriteFile(test.targets[0], []byte(`0.0.0.0`), 0000) ioutil.WriteFile(test.targets[0], []byte(`0.0.0.0`), 0000)
} }
if !test.loadCredsFail { if !test.loadCredsFail && test.customCredentials == "" {
test.customCredentials = generateTmpFileName(i, "creds") test.customCredentials = generateTmpFileName(i, "creds")
ioutil.WriteFile(test.customCredentials, []byte(`{"usernames":["admin"],"passwords":["admin"]}`), 0644) ioutil.WriteFile(test.customCredentials, []byte(`{"usernames":["admin"],"passwords":["admin"]}`), 0644)
} }
if !test.loadRoutesFail { if !test.loadRoutesFail && test.customRoutes == "" {
test.customRoutes = generateTmpFileName(i, "routes") test.customRoutes = generateTmpFileName(i, "routes")
ioutil.WriteFile(test.customRoutes, []byte(`live.sdp`), 0644) ioutil.WriteFile(test.customRoutes, []byte(`live.sdp`), 0644)
} }