Commit 18e47028 authored by Sophie Brun's avatar Sophie Brun

Update upstream source from tag 'upstream/2.6'

Update to upstream version '2.6'
with Debian dir 24c3bfe1cfea57a14c6fc543df5f2816354d9a48
parents fd0f9610 8e9eb9e0
language: go
sudo: false
language: go
go:
- 1.9.3
- 1.8.x
- 1.9.x
- 1.10.x
- master
matrix:
# It's ok if our code fails on unstable development versions of Go.
allow_failures:
- go: master
# Don't wait for tip tests to finish. Mark the test run green if the
# tests pass on the stable versions of Go.
fast_finish: true
notifications:
email: false
git:
depth: 3
......@@ -9,13 +24,13 @@ git:
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libpcap-dev libnetfilter-queue-dev
- go get -u github.com/golang/dep/...
install:
- make deps
go_import_path: github.com/bettercap/bettercap
script:
- make test
after_success:
- bash <(curl -s https://codecov.io/bash)
# build stage
FROM golang:1.10-alpine AS build-env
FROM golang:alpine AS build-env
ENV SRC_DIR $GOPATH/src/github.com/bettercap/bettercap
RUN apk add --update ca-certificates
RUN apk add --update ca-certificates
RUN apk add --no-cache --update bash iptables wireless-tools build-base libpcap-dev linux-headers libnetfilter_queue-dev git
WORKDIR $SRC_DIR
......@@ -12,10 +12,15 @@ RUN go get -u github.com/golang/dep/...
RUN make deps
RUN make
# get caplets
RUN git clone https://github.com/bettercap/caplets
# final stage
FROM alpine
RUN apk add --no-cache --update bash iproute2 libpcap libnetfilter_queue
RUN apk add --no-cache --update bash iproute2 libpcap libnetfilter_queue wireless-tools
COPY --from=build-env /go/src/github.com/bettercap/bettercap/bettercap /app/
COPY --from=build-env /go/src/github.com/bettercap/bettercap/caplets /app/
WORKDIR /app
EXPOSE 80 443 53 5300 8080 8081 8082 8083 8000
ENTRYPOINT ["/app/bettercap"]
......@@ -19,7 +19,7 @@
"linux/util",
"xpc"
]
revision = "e65eb2df9116e5ec6e2409b6142a09a93e96b900"
revision = "66e7446993acb3de936b3f487e5933522ed16923"
[[projects]]
name = "github.com/bettercap/readline"
......@@ -37,7 +37,7 @@
branch = "master"
name = "github.com/dustin/go-humanize"
packages = ["."]
revision = "bb3d318650d48840a39aa21a027c6630e198e626"
revision = "02af3965c54e8cacf948b97fef38925c4120652c"
[[projects]]
branch = "master"
......@@ -84,10 +84,10 @@
version = "v1.1.14"
[[projects]]
branch = "master"
name = "github.com/gorilla/context"
packages = ["."]
revision = "08b5f424b9271eedf6f9f0ce86cb9396ed337a42"
revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a"
version = "v1.1"
[[projects]]
name = "github.com/gorilla/mux"
......@@ -122,7 +122,8 @@
[[projects]]
name = "github.com/mattn/go-colorable"
packages = ["."]
revision = "5411d3eea5978e6cdc258b30de592b60df6aba96"
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
version = "v0.0.9"
[[projects]]
name = "github.com/mattn/go-isatty"
......@@ -153,10 +154,10 @@
version = "v1"
[[projects]]
branch = "master"
name = "github.com/pkg/errors"
packages = ["."]
revision = "816c9085562cd7ee03e7f8188a1cfd942858cded"
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]]
branch = "master"
......@@ -170,7 +171,7 @@
"registry",
"token"
]
revision = "6c383dd335ef8dcccef05e651ce1eccfe4d0f011"
revision = "03d472dc43abece8691e609a23d295ab732abba6"
[[projects]]
branch = "master"
......@@ -179,9 +180,10 @@
revision = "eaafced92e9619f03c72527efeab21e326f3bc36"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "abf9c25f54453410d0c6668e519582a9e1115027"
revision = "d0faeb539838e250bd0a9db4182d48d4a1915181"
[[projects]]
name = "gopkg.in/sourcemap.v1"
......@@ -195,6 +197,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "16887d6924226ea7174b18c0c2a92da30997904da44648f7df6927b3ec8e8de1"
inputs-digest = "2b0f222c61ea5761232c564da1ab8bd87de5daf61b4ba4ebc89e8f0965a89f95"
solver-name = "gps-cdcl"
solver-version = 1
TARGET=bettercap
PACKAGES=core firewall log modules network packets session tls
all: fmt vet build
@echo "@ Done"
all: deps build
test: build
@go test ./...
deps: godep golint gomegacheck
@dep ensure
build: resources
@echo "@ Building ..."
@go build -o $(TARGET) .
resources: network/oui.go
......@@ -15,19 +14,40 @@ resources: network/oui.go
network/oui.go:
@python ./network/make_oui.py
vet:
@go vet ./...
fmt:
@go fmt ./...
lint:
@golint ./...
deps:
@dep ensure
clean:
@rm -rf $(TARGET).*
@rm -rf $(TARGET)*
@rm -rf build
docker:
@docker build -t bettercap:latest .
# Go 1.9 doesn't support test coverage on multiple packages, while
# Go 1.10 does, let's keep it 1.9 compatible in order not to break
# travis
test: deps
@echo "mode: atomic" > coverage.profile
@for pkg in $(PACKAGES); do \
go fmt ./$$pkg ; \
go vet ./$$pkg ; \
megacheck ./$$pkg ; \
touch $$pkg.profile ; \
go test -race ./$$pkg -coverprofile=$$pkg.profile -covermode=atomic; \
tail -n +2 $$pkg.profile >> coverage.profile && rm -rf $$pkg.profile ; \
done
html_coverage: test
@go tool cover -html=coverage.profile -o coverage.profile.html
benchmark: server_deps
@go test ./... -v -run=doNotRunTests -bench=. -benchmem
# tools
godep:
@go get -u github.com/golang/dep/...
golint:
@go get github.com/golang/lint/golint
gomegacheck:
@go get honnef.co/go/tools/cmd/megacheck
......@@ -5,6 +5,7 @@
<a href="https://github.com/bettercap/bettercap/blob/master/LICENSE.md"><img alt="Software License" src="https://img.shields.io/badge/license-GPL3-brightgreen.svg?style=flat-square"></a>
<a href="https://travis-ci.org/bettercap/bettercap"><img alt="Travis" src="https://img.shields.io/travis/bettercap/bettercap/master.svg?style=flat-square"></a>
<a href="https://goreportcard.com/report/github.com/bettercap/bettercap"><img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/bettercap/bettercap?style=flat-square&fuckgithubcache=1"></a>
<a href="https://codecov.io/gh/bettercap/bettercap"><img alt="Code Coverage" src="https://img.shields.io/codecov/c/github/bettercap/bettercap/master.svg?style=flat-square"></a>
</p>
</p>
......
......@@ -2,7 +2,7 @@ package core
const (
Name = "bettercap"
Version = "2.5"
Version = "2.6"
Author = "Simone 'evilsocket' Margaritelli"
Website = "https://bettercap.org/"
)
package core
import (
"regexp"
"testing"
)
func TestBannerName(t *testing.T) {
if Name != "bettercap" {
t.Fatalf("expected '%s', got '%s'", "bettercap", Name)
}
}
func TestBannerWebsite(t *testing.T) {
if Website != "https://bettercap.org/" {
t.Fatalf("expected '%s', got '%s'", "https://bettercap.org/", Website)
}
}
func TestBannerVersion(t *testing.T) {
match, err := regexp.MatchString(`\d+.\d+`, Version)
if err != nil {
t.Fatalf("unable to perform regex on Version constant")
}
if !match {
t.Fatalf("expected Version constant in format '%s', got '%s'", "X.X", Version)
}
}
func TestBannerAuthor(t *testing.T) {
if Author != "Simone 'evilsocket' Margaritelli" {
t.Fatalf("expected '%s', got '%s'", "Simone 'evilsocket' Margaritelli", Author)
}
}
......@@ -30,7 +30,7 @@ func UniqueInts(a []int, sorted bool) []int {
tmp[n] = true
}
for n, _ := range tmp {
for n := range tmp {
uniq = append(uniq, n)
}
......@@ -72,18 +72,11 @@ func ExecSilent(executable string, args []string) (string, error) {
}
func Exec(executable string, args []string) (string, error) {
path, err := exec.LookPath(executable)
out, err := ExecSilent(executable, args)
if err != nil {
return "", err
}
raw, err := exec.Command(path, args...).CombinedOutput()
if err != nil {
fmt.Printf("ERROR: path=%s args=%s err=%s out='%s'\n", path, args, err, raw)
return "", err
} else {
return Trim(string(raw)), nil
fmt.Printf("ERROR for '%s %s': %s\n", executable, args, err)
}
return out, err
}
func Exists(path string) bool {
......@@ -100,9 +93,10 @@ func ExpandPath(path string) (string, error) {
usr, err := user.Current()
if err != nil {
return "", err
} else {
// Replace only the first occurrence of ~
path = strings.Replace(path, "~", usr.HomeDir, 1)
}
// Replace only the first occurrence of ~
path = strings.Replace(path, "~", usr.HomeDir, 1)
}
return filepath.Abs(path)
}
......
package core
import (
"bytes"
"io"
"os"
"os/user"
"path/filepath"
"testing"
)
func TestCoreTrim(t *testing.T) {
var units = []struct {
from string
to string
}{
{"\t ", ""},
{" ", ""},
{" hello world", "hello world"},
{"hello world ", "hello world"},
{" hello world\t", "hello world"},
}
for _, u := range units {
got := Trim(u.from)
if got != u.to {
t.Fatalf("expected '%s', got '%s'", u.to, got)
}
}
}
func TestCoreTrimRight(t *testing.T) {
var units = []struct {
from string
to string
}{
{"\t ", ""},
{" ", ""},
{" hello world", " hello world"},
{"hello world ", "hello world"},
{" hello world\t", " hello world"},
}
for _, u := range units {
got := TrimRight(u.from)
if got != u.to {
t.Fatalf("expected '%s', got '%s'", u.to, got)
}
}
}
func hasInt(a []int, v int) bool {
for _, n := range a {
if n == v {
return true
}
}
return false
}
func sameInts(a []int, b []int, ordered bool) bool {
if len(a) != len(b) {
return false
}
if ordered {
for i, v := range a {
if v != b[i] {
return false
}
}
} else {
for _, v := range a {
if !hasInt(b, v) {
return false
}
}
}
return true
}
func TestCoreUniqueIntsUnsorted(t *testing.T) {
var units = []struct {
from []int
to []int
}{
{[]int{}, []int{}},
{[]int{1, 1, 1, 1, 1}, []int{1}},
{[]int{1, 2, 1, 2, 3, 4}, []int{1, 2, 3, 4}},
{[]int{4, 3, 4, 3, 2, 2}, []int{4, 3, 2}},
{[]int{8, 3, 8, 4, 6, 1}, []int{8, 3, 4, 6, 1}},
}
for _, u := range units {
got := UniqueInts(u.from, false)
if !sameInts(got, u.to, false) {
t.Fatalf("expected '%v', got '%v'", u.to, got)
}
}
}
func TestCoreUniqueIntsSorted(t *testing.T) {
var units = []struct {
from []int
to []int
}{
{[]int{}, []int{}},
{[]int{1, 1, 1, 1, 1}, []int{1}},
{[]int{1, 2, 1, 2, 3, 4}, []int{1, 2, 3, 4}},
{[]int{4, 3, 4, 3, 2, 2}, []int{2, 3, 4}},
{[]int{8, 3, 8, 4, 6, 1}, []int{1, 3, 4, 6, 8}},
}
for _, u := range units {
got := UniqueInts(u.from, true)
if !sameInts(got, u.to, true) {
t.Fatalf("expected '%v', got '%v'", u.to, got)
}
}
}
func sameStrings(a []string, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func TestCoreSepSplitAndCommaSplit(t *testing.T) {
var units = []struct {
from string
to []string
}{
{"foo", []string{"foo"}},
{"foo#bar", []string{"foo#bar"}},
{"foo,bar", []string{"foo", "bar"}},
{"foo,bar,", []string{"foo", "bar"}},
{"foo,bar,", []string{"foo", "bar"}},
{"foo,,bar,", []string{"foo", "bar"}},
{"foo,,bar,,,,", []string{"foo", "bar"}},
{"foo,bar@wut,.ok", []string{"foo", "bar@wut", ".ok"}},
}
for _, u := range units {
if got := SepSplit(u.from, ","); !sameStrings(got, u.to) {
t.Fatalf("expected '%v', got '%v'", u.to, got)
} else if got = CommaSplit(u.from); !sameStrings(got, u.to) {
t.Fatalf("expected '%v', got '%v'", u.to, got)
}
}
}
func TestCoreExec(t *testing.T) {
var units = []struct {
exec string
args []string
out string
err string
stdout string
}{
{"foo", []string{}, "", `exec: "foo": executable file not found in $PATH`, `ERROR for 'foo []': exec: "foo": executable file not found in $PATH`},
{"ps", []string{"-someinvalidflag"}, "", "exit status 1", "ERROR for 'ps [-someinvalidflag]': exit status 1"},
{"true", []string{}, "", "", ""},
{"head", []string{"/path/to/file/that/does/not/exist"}, "", "exit status 1", "ERROR for 'head [/path/to/file/that/does/not/exist]': exit status 1"},
}
for _, u := range units {
var buf bytes.Buffer
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
gotOut, gotErr := ExecSilent(u.exec, u.args)
w.Close()
io.Copy(&buf, r)
os.Stdout = oldStdout
gotStdout := Trim(buf.String())
if gotOut != u.out {
t.Fatalf("expected output '%s', got '%s'", u.out, gotOut)
} else if u.err == "" && gotErr != nil {
t.Fatalf("expected no error, got '%s'", gotErr)
} else if u.err != "" && gotErr == nil {
t.Fatalf("expected error '%s', got none", u.err)
} else if u.err != "" && gotErr != nil && gotErr.Error() != u.err {
t.Fatalf("expected error '%s', got '%s'", u.err, gotErr)
} else if gotStdout != "" {
t.Fatalf("expected empty stdout, got '%s'", gotStdout)
}
}
for _, u := range units {
var buf bytes.Buffer
oldStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
gotOut, gotErr := Exec(u.exec, u.args)
w.Close()
io.Copy(&buf, r)
os.Stdout = oldStdout
gotStdout := Trim(buf.String())
if gotOut != u.out {
t.Fatalf("expected output '%s', got '%s'", u.out, gotOut)
} else if u.err == "" && gotErr != nil {
t.Fatalf("expected no error, got '%s'", gotErr)
} else if u.err != "" && gotErr == nil {
t.Fatalf("expected error '%s', got none", u.err)
} else if u.err != "" && gotErr != nil && gotErr.Error() != u.err {
t.Fatalf("expected error '%s', got '%s'", u.err, gotErr)
} else if gotStdout != u.stdout {
t.Fatalf("expected stdout '%s', got '%s'", u.stdout, gotStdout)
}
}
}
func TestCoreExists(t *testing.T) {
var units = []struct {
what string
exists bool
}{
{".", true},
{"/", true},
{"wuuut", false},
{"/wuuu.t", false},
{os.Args[0], true},
}
for _, u := range units {
got := Exists(u.what)
if got != u.exists {
t.Fatalf("expected '%v', got '%v'", u.exists, got)
}
}
}
func TestCoreExpandPath(t *testing.T) {
base, _ := filepath.Abs(".")
usr, _ := user.Current()
var units = []struct {
from string
to string
err string
}{
{"", "", ""},
{"/lulz", "/lulz", ""},
{".", base, ""},
{"~", usr.HomeDir, ""},
}
for _, u := range units {
gotPath, gotErr := ExpandPath(u.from)
if gotPath != u.to {
t.Fatalf("expected path '%s', got '%s'", u.to, gotPath)
} else if u.err == "" && gotErr != nil {
t.Fatalf("expected no error, got '%v'", gotErr)
} else if u.err != "" && gotErr == nil {
t.Fatalf("expected error '%s', got none", u.err)
} else if u.err != "" && gotErr != nil && gotErr.Error() != u.err {
t.Fatalf("expected error '%s', got '%s'", u.err, gotErr.Error())
}
}
}
......@@ -25,7 +25,7 @@ func ParseOptions() (Options, error) {
Silent: flag.Bool("silent", false, "Suppress all logs which are not errors."),
NoColors: flag.Bool("no-colors", false, "Disable output color effects."),
NoHistory: flag.Bool("no-history", false, "Disable interactive session history file."),
EnvFile: flag.String("env-file", "", "Load environment variables from this file if found, set to empty to disable environment persistance."),
EnvFile: flag.String("env-file", "", "Load environment variables from this file if found, set to empty to disable environment persistence."),