Commit 09b99ff8 authored by Sophie Brun's avatar Sophie Brun

New upstream version 2.11

parent 171ceb97
......@@ -4,6 +4,7 @@ language: go
go:
- 1.9.x
- 1.10.x
- 1.11.x
- master
matrix:
......
......@@ -52,15 +52,31 @@
[[projects]]
branch = "master"
digest = "1:2b7b174ae68705866555b73fd848de0749b93b1f99e3295e27f89bebe8702203"
digest = "1:7dc5d77e0d21759f0ba62f928f15519c961eee6a4ada94558d94094ccd792faa"
name = "github.com/elazarl/goproxy"
packages = ["."]
pruneopts = "UT"
revision = "947c36da3153ff334e74d9d980de341d25f358ba"
revision = "f58a169a71a51037728990b2d3597a14f56b525b"
[[projects]]
digest = "1:495dc25bbfe6025e945e3efe885801fc1aefc33d835cac453c0e36a35693d839"
name = "github.com/evilsocket/islazy"
packages = [
"data",
"fs",
"log",
"plugin",
"str",
"tui",
"zip",
]
pruneopts = "UT"
revision = "3d8400c74f9dbc626d913e0575cda05d914bea57"
version = "v1.9.1"
[[projects]]
branch = "master"
digest = "1:f46dd7c5783c6caa5ea1072eb4165446c58651ff0849c9d366ac318f140661fa"
digest = "1:e5e45557e1871c967a6ccaa5b95d1233a2c01ab00615621825d1aca7383dc022"
name = "github.com/gobwas/glob"
packages = [
".",
......@@ -73,7 +89,7 @@
"util/strings",
]
pruneopts = "UT"
revision = "f756513aec94125582ee6c0dc94179251ef87370"
revision = "e7a84e9525fe90abcda167b604e483cc959ad4aa"
[[projects]]
digest = "1:51bee9f1987dcdb9f9a1b4c20745d78f6bf6f5f14ad4e64ca883eb64df4c0045"
......@@ -84,15 +100,15 @@
version = "v15.0.0"
[[projects]]
branch = "master"
digest = "1:a63cff6b5d8b95638bfe300385d93b2a6d9d687734b863da8e09dc834510a690"
name = "github.com/google/go-querystring"
packages = ["query"]
pruneopts = "UT"
revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a"
revision = "44c6ddd0a2342c386950e880b658017258da92fc"
version = "v1.0.0"
[[projects]]
digest = "1:a1b2a09d080e0229db471efc7f030b6d3931cd54989f6a1a4d676e085139cc2d"
digest = "1:65e00adfb37f64ce3c24f139bc73db70bfe45224ebaf88250eff4038e32ac9cf"
name = "github.com/google/gopacket"
packages = [
".",
......@@ -101,8 +117,7 @@
"pcapgo",
]
pruneopts = "UT"
revision = "11c65f1ca9081dfea43b4f9643f5c155583b73ba"
version = "v1.1.14"
revision = "d67ddb98d5a1b7c79a8977ec2d552e1db45eda86"
[[projects]]
digest = "1:c79fb010be38a59d657c48c6ba1d003a8aa651fa56b579d959d74573b7dff8e1"
......@@ -180,6 +195,14 @@
pruneopts = "UT"
revision = "e26af0688e455a82b14ebdbecf43f87ead3c4624"
[[projects]]
branch = "master"
digest = "1:6569c2877d56f921a8a459d182af16b700c0e588c94b9938aef0d15d13d596db"
name = "github.com/mdlayher/raw"
packages = ["."]
pruneopts = "UT"
revision = "67a536258490ec29bca6d465b51dea32c0db3623"
[[projects]]
branch = "master"
digest = "1:2b32af4d2a529083275afc192d1067d8126b578c7a9613b26600e4df9c735155"
......@@ -230,11 +253,19 @@
[[projects]]
branch = "master"
digest = "1:6eb2645d74b43d9c87b51947df39f7c668a4f422cd512053f7f6f75bfaad0197"
digest = "1:b45576bdf553b4c64ff798345b3256e49a157f8b480d29c8c0a89f09119d6c5a"
name = "golang.org/x/net"
packages = ["bpf"]
pruneopts = "UT"
revision = "49bb7cea24b1df9410e1712aa6433dae904ff66a"
[[projects]]
branch = "master"
digest = "1:0a40b0bdd57a93e741d8557465be3a2edeec408e9b6399586ad65bbe8e355796"
name = "golang.org/x/sys"
packages = ["unix"]
pruneopts = "UT"
revision = "d0be0721c37eeb5299f245a996a483160fc36940"
revision = "fa43e7bc11baaae89f3f902b2b4d832b68234844"
[[projects]]
digest = "1:9935525a8c49b8434a0b0a54e1980e94a6fae73aaff45c5d33ba8dff69de123e"
......@@ -257,6 +288,13 @@
"github.com/chifflier/nfqueue-go/nfqueue",
"github.com/dustin/go-humanize",
"github.com/elazarl/goproxy",
"github.com/evilsocket/islazy/data",
"github.com/evilsocket/islazy/fs",
"github.com/evilsocket/islazy/log",
"github.com/evilsocket/islazy/plugin",
"github.com/evilsocket/islazy/str",
"github.com/evilsocket/islazy/tui",
"github.com/evilsocket/islazy/zip",
"github.com/gobwas/glob",
"github.com/google/go-github/github",
"github.com/google/gopacket",
......@@ -268,7 +306,6 @@
"github.com/inconshreveable/go-vhost",
"github.com/jpillora/go-tld",
"github.com/malfunkt/iprange",
"github.com/mattn/go-isatty",
"github.com/mdlayher/dhcp6",
"github.com/mdlayher/dhcp6/dhcp6opts",
"github.com/robertkrimen/otto",
......
......@@ -23,7 +23,9 @@
# non-go = false
# go-tests = true
# unused-packages = true
[[constraint]]
name = "github.com/evilsocket/islazy"
version = "1.9.1"
[[constraint]]
branch = "master"
......@@ -55,7 +57,7 @@
[[constraint]]
name = "github.com/google/gopacket"
version = "1.1.14"
revision = "d67ddb98d5a1b7c79a8977ec2d552e1db45eda86"
[[constraint]]
name = "github.com/gorilla/mux"
......@@ -77,10 +79,6 @@
name = "github.com/malfunkt/iprange"
version = "0.9.0"
[[constraint]]
name = "github.com/mattn/go-isatty"
version = "0.0.3"
[[constraint]]
branch = "master"
name = "github.com/mdlayher/dhcp6"
......
......@@ -3,7 +3,7 @@ PACKAGES=core firewall log modules network packets session tls
all: deps build
deps: godep golint gomegacheck
deps: godep golint gofmt gomegacheck
@dep ensure
build: resources
......@@ -50,7 +50,10 @@ godep:
@go get -u github.com/golang/dep/...
golint:
@go get github.com/golang/lint/golint
@go get -u golang.org/x/lint/golint
gomegacheck:
@go get honnef.co/go/tools/cmd/megacheck
gofmt:
gofmt -s -w $(PACKAGES)
\ No newline at end of file
......@@ -2,9 +2,10 @@ package caplets
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/evilsocket/islazy/fs"
)
type Caplet struct {
......@@ -15,39 +16,23 @@ type Caplet struct {
}
func (cap *Caplet) Eval(argv []string, lineCb func(line string) error) error {
// the caplet might include other files (include directive, proxy modules, etc),
// temporarily change the working directory
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("error while getting current working directory: %v", err)
}
capPath := filepath.Dir(cap.Path)
if err := os.Chdir(capPath); err != nil {
return fmt.Errorf("error while changing current working directory: %v", err)
}
defer func() {
if err := os.Chdir(cwd); err != nil {
fmt.Printf("error while restoring working directory: %v\n", err)
}
}()
if argv == nil {
argv = []string{}
}
for _, line := range cap.Code {
// replace $0 with argv[0], $1 with argv[1] and so on
for i, arg := range argv {
what := fmt.Sprintf("$%d", i)
line = strings.Replace(line, what, arg, -1)
}
if err = lineCb(line); err != nil {
return err
// the caplet might include other files (include directive, proxy modules, etc),
// temporarily change the working directory
return fs.Chdir(filepath.Dir(cap.Path), func() error {
for _, line := range cap.Code {
// replace $0 with argv[0], $1 with argv[1] and so on
for i, arg := range argv {
what := fmt.Sprintf("$%d", i)
line = strings.Replace(line, what, arg, -1)
}
if err := lineCb(line); err != nil {
return err
}
}
}
return nil
return nil
})
}
......@@ -4,7 +4,7 @@ import (
"os"
"path/filepath"
"github.com/bettercap/bettercap/core"
"github.com/evilsocket/islazy/str"
)
const (
......@@ -26,8 +26,8 @@ var (
)
func init() {
for _, path := range core.SepSplit(core.Trim(os.Getenv(EnvVarName)), ":") {
if path = core.Trim(path); len(path) > 0 {
for _, path := range str.SplitBy(str.Trim(os.Getenv(EnvVarName)), ":") {
if path = str.Trim(path); len(path) > 0 {
LoadPaths = append(LoadPaths, path)
}
}
......
package caplets
import (
"bufio"
"fmt"
"os"
"path/filepath"
......@@ -9,7 +8,7 @@ import (
"strings"
"sync"
"github.com/bettercap/bettercap/core"
"github.com/evilsocket/islazy/fs"
)
var (
......@@ -62,29 +61,24 @@ func Load(name string) (error, *Caplet) {
}
for _, filename := range names {
if core.Exists(filename) {
if fs.Exists(filename) {
cap := &Caplet{
Path: filename,
Code: make([]string, 0),
}
cache[name] = cap
input, err := os.Open(filename)
if err != nil {
if reader, err := fs.LineReader(filename); err != nil {
return fmt.Errorf("error reading caplet %s: %v", filename, err), nil
}
defer input.Close()
scanner := bufio.NewScanner(input)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
line := core.Trim(scanner.Text())
if line == "" || line[0] == '#' {
continue
} else {
for line := range reader {
if line == "" || line[0] == '#' {
continue
}
cap.Code = append(cap.Code, line)
}
cap.Code = append(cap.Code, line)
}
cache[name] = cap
return nil, cap
}
}
......
......@@ -2,7 +2,7 @@ package core
const (
Name = "bettercap"
Version = "2.10"
Version = "2.11"
Author = "Simone 'evilsocket' Margaritelli"
Website = "https://bettercap.org/"
)
package core
import (
"archive/zip"
"fmt"
"io"
"os"
"os/exec"
"os/user"
"path/filepath"
"sort"
"strings"
)
const (
defaultTrimSet = "\r\n\t "
"github.com/evilsocket/islazy/str"
)
func Trim(s string) string {
return strings.Trim(s, defaultTrimSet)
}
func TrimRight(s string) string {
return strings.TrimRight(s, defaultTrimSet)
}
func UniqueInts(a []int, sorted bool) []int {
tmp := make(map[int]bool)
uniq := make([]int, 0)
......@@ -43,22 +27,6 @@ func UniqueInts(a []int, sorted bool) []int {
return uniq
}
func SepSplit(sv string, sep string) []string {
filtered := make([]string, 0)
for _, part := range strings.Split(sv, sep) {
part = Trim(part)
if part != "" {
filtered = append(filtered, part)
}
}
return filtered
}
func CommaSplit(csv string) []string {
return SepSplit(csv, ",")
}
func ExecSilent(executable string, args []string) (string, error) {
path, err := exec.LookPath(executable)
if err != nil {
......@@ -69,7 +37,7 @@ func ExecSilent(executable string, args []string) (string, error) {
if err != nil {
return "", err
} else {
return Trim(string(raw)), nil
return str.Trim(string(raw)), nil
}
}
......@@ -80,72 +48,3 @@ func Exec(executable string, args []string) (string, error) {
}
return out, err
}
func Exists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}
func ExpandPath(path string) (string, error) {
// Check if path is empty
if path != "" {
if strings.HasPrefix(path, "~") {
usr, err := user.Current()
if err != nil {
return "", err
} else {
// Replace only the first occurrence of ~
path = strings.Replace(path, "~", usr.HomeDir, 1)
}
}
return filepath.Abs(path)
}
return "", nil
}
// Unzip will decompress a zip archive, moving all files and folders
// within the zip file (parameter 1) to an output directory (parameter 2).
// Credits to https://golangcode.com/unzip-files-in-go/
func Unzip(src string, dest string) ([]string, error) {
var filenames []string
r, err := zip.OpenReader(src)
if err != nil {
return filenames, err
}
defer r.Close()
for _, f := range r.File {
rc, err := f.Open()
if err != nil {
return filenames, err
}
defer rc.Close()
// Store filename/path for returning and using later on
fpath := filepath.Join(dest, f.Name)
// Check for ZipSlip. More Info: https://snyk.io/research/zip-slip-vulnerability#go
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
return filenames, fmt.Errorf("%s: illegal file path", fpath)
}
filenames = append(filenames, fpath)
if f.FileInfo().IsDir() {
os.MkdirAll(fpath, os.ModePerm)
} else if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
return filenames, err
} else if outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()); err != nil {
return filenames, err
} else {
defer outFile.Close()
if _, err = io.Copy(outFile, rc); err != nil {
return filenames, err
}
}
}
return filenames, nil
}
......@@ -4,50 +4,11 @@ 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)
}
}
}
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/str"
)
func hasInt(a []int, v int) bool {
for _, n := range a {
......@@ -132,30 +93,6 @@ func sameStrings(a []string, b []string) bool {
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
......@@ -182,7 +119,7 @@ func TestCoreExec(t *testing.T) {
io.Copy(&buf, r)
os.Stdout = oldStdout
gotStdout := Trim(buf.String())
gotStdout := str.Trim(buf.String())
if gotOut != u.out {
t.Fatalf("expected output '%s', got '%s'", u.out, gotOut)
} else if u.err == "" && gotErr != nil {
......@@ -208,7 +145,7 @@ func TestCoreExec(t *testing.T) {
io.Copy(&buf, r)
os.Stdout = oldStdout
gotStdout := Trim(buf.String())
gotStdout := str.Trim(buf.String())
if gotOut != u.out {
t.Fatalf("expected output '%s', got '%s'", u.out, gotOut)
} else if u.err == "" && gotErr != nil {
......@@ -236,38 +173,9 @@ func TestCoreExists(t *testing.T) {
}
for _, u := range units {
got := Exists(u.what)
got := fs.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())
}
}
}