refact: refactored to use islazy and updated deps

This commit is contained in:
evilsocket 2018-10-10 19:00:25 +02:00
parent a2b3ee79fb
commit d070445225
238 changed files with 12662 additions and 1586 deletions

View file

@ -6,13 +6,14 @@ import (
"net/http"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/bettercap/bettercap/tls"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/evilsocket/islazy/fs"
)
type RestAPI struct {
@ -135,11 +136,11 @@ func (api *RestAPI) Configure() error {
return err
} else if err, api.certFile = api.StringParam("api.rest.certificate"); err != nil {
return err
} else if api.certFile, err = core.ExpandPath(api.certFile); err != nil {
} else if api.certFile, err = fs.Expand(api.certFile); err != nil {
return err
} else if err, api.keyFile = api.StringParam("api.rest.key"); err != nil {
return err
} else if api.keyFile, err = core.ExpandPath(api.keyFile); err != nil {
} else if api.keyFile, err = fs.Expand(api.keyFile); err != nil {
return err
} else if err, api.username = api.StringParam("api.rest.username"); err != nil {
return err
@ -150,7 +151,7 @@ func (api *RestAPI) Configure() error {
}
if api.isTLS() {
if !core.Exists(api.certFile) || !core.Exists(api.keyFile) {
if !fs.Exists(api.certFile) || !fs.Exists(api.keyFile) {
err, cfg := tls.CertConfigFromModule("api.rest", api.SessionModule)
if err != nil {
return err

View file

@ -11,11 +11,12 @@ import (
"strings"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/gatt"
"github.com/evilsocket/islazy/tui"
)
var (
@ -30,15 +31,15 @@ func (d *BLERecon) getRow(dev *network.BLEDevice) []string {
lastSeen := dev.LastSeen.Format("15:04:05")
if sinceSeen <= bleAliveInterval {
lastSeen = core.Bold(lastSeen)
lastSeen = tui.Bold(lastSeen)
} else if sinceSeen > blePresentInterval {
lastSeen = core.Dim(lastSeen)
address = core.Dim(address)
lastSeen = tui.Dim(lastSeen)
address = tui.Dim(address)
}
isConnectable := core.Red("no")
isConnectable := tui.Red("no")
if dev.Advertisement.Connectable {
isConnectable = core.Green("yes")
isConnectable = tui.Green("yes")
}
return []string{
@ -65,7 +66,7 @@ func (d *BLERecon) Show() error {
columns := []string{"RSSI", "Address", "Name", "Vendor", "Connectable", "Last Seen"}
if nrows > 0 {
core.AsTable(os.Stdout, columns, rows)
tui.Table(os.Stdout, columns, rows)
}
d.Session.Refresh()
@ -87,7 +88,7 @@ func parseProperties(ch *gatt.Characteristic) (props []string, isReadable bool,
props = append(props, "read")
}
if (mask&gatt.CharWriteNR) != 0 || (mask&gatt.CharWrite) != 0 {
props = append(props, core.Bold("write"))
props = append(props, tui.Bold("write"))
isWritable = true
withResponse = (mask & gatt.CharWriteNR) == 0
}
@ -98,7 +99,7 @@ func parseProperties(ch *gatt.Characteristic) (props []string, isReadable bool,
props = append(props, "indicate")
}
if (mask & gatt.CharSignedWrite) != 0 {
props = append(props, core.Yellow("*write"))
props = append(props, tui.Yellow("*write"))
isWritable = true
withResponse = true
}
@ -121,7 +122,7 @@ func parseRawData(raw []byte) string {
}
}
return core.Yellow(s)
return tui.Yellow(s)
}
func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
@ -138,7 +139,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
if name == "" {
name = svc.UUID().String()
} else {
name = fmt.Sprintf("%s (%s)", core.Green(name), core.Dim(svc.UUID().String()))
name = fmt.Sprintf("%s (%s)", tui.Green(name), tui.Dim(svc.UUID().String()))
}
row := []string{
@ -163,7 +164,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
if name == "" {
name = " " + ch.UUID().String()
} else {
name = fmt.Sprintf(" %s (%s)", core.Green(name), core.Dim(ch.UUID().String()))
name = fmt.Sprintf(" %s (%s)", tui.Green(name), tui.Dim(ch.UUID().String()))
}
props, isReadable, isWritable, withResponse := parseProperties(ch)
@ -186,7 +187,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
if isReadable {
raw, err := p.ReadCharacteristic(ch)
if err != nil {
data = core.Red(err.Error())
data = tui.Red(err.Error())
} else {
data = parseRawData(raw)
}
@ -206,7 +207,7 @@ func (d *BLERecon) showServices(p gatt.Peripheral, services []*gatt.Service) {
if wantsToWrite && !foundToWrite {
log.Error("Writable characteristics %s not found.", d.writeUUID)
} else {
core.AsTable(os.Stdout, columns, rows)
tui.Table(os.Stdout, columns, rows)
d.Session.Refresh()
}
}

View file

@ -7,11 +7,14 @@ import (
"os"
"github.com/bettercap/bettercap/caplets"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/dustin/go-humanize"
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/tui"
"github.com/evilsocket/islazy/zip"
)
type CapletsModule struct {
@ -83,13 +86,13 @@ func (c *CapletsModule) Show() error {
for _, caplet := range caplets {
rows = append(rows, []string{
core.Bold(caplet.Name),
tui.Bold(caplet.Name),
caplet.Path,
core.Dim(humanize.Bytes(uint64(caplet.Size))),
tui.Dim(humanize.Bytes(uint64(caplet.Size))),
})
}
core.AsTable(os.Stdout, colNames, rows)
tui.Table(os.Stdout, colNames, rows)
return nil
}
@ -104,14 +107,14 @@ func (c *CapletsModule) Paths() error {
rows = append(rows, []string{path})
}
core.AsTable(os.Stdout, colNames, rows)
fmt.Printf("(paths can be customized by defining the %s environment variable)\n", core.Bold(caplets.EnvVarName))
tui.Table(os.Stdout, colNames, rows)
fmt.Printf("(paths can be customized by defining the %s environment variable)\n", tui.Bold(caplets.EnvVarName))
return nil
}
func (c *CapletsModule) Update() error {
if !core.Exists(caplets.InstallBase) {
if !fs.Exists(caplets.InstallBase) {
log.Info("creating caplets install path %s ...", caplets.InstallBase)
if err := os.MkdirAll(caplets.InstallBase, os.ModePerm); err != nil {
return err
@ -138,7 +141,7 @@ func (c *CapletsModule) Update() error {
log.Info("installing caplets to %s ...", caplets.InstallPath)
if _, err = core.Unzip("/tmp/caplets.zip", caplets.InstallBase); err != nil {
if _, err = zip.Unzip("/tmp/caplets.zip", caplets.InstallBase); err != nil {
return err
}

View file

@ -9,7 +9,6 @@ import (
"sync"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
@ -22,6 +21,8 @@ import (
// will fix this > https://github.com/google/gopacket/issues/334
"github.com/mdlayher/dhcp6"
"github.com/mdlayher/dhcp6/dhcp6opts"
"github.com/evilsocket/islazy/tui"
)
type DHCP6Spoofer struct {
@ -130,7 +131,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
fqdn = string(raw[0])
}
log.Info("[%s] Got DHCPv6 Solicit request from %s (%s), sending spoofed advertisement for %d domains.", core.Green("dhcp6"), core.Bold(fqdn), target, len(s.Domains))
log.Info("[%s] Got DHCPv6 Solicit request from %s (%s), sending spoofed advertisement for %d domains.", tui.Green("dhcp6"), tui.Bold(fqdn), target, len(s.Domains))
err, adv := s.dhcp6For(dhcp6.MessageTypeAdvertise, solicit)
if err != nil {
@ -224,7 +225,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
}
func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.Packet, target net.HardwareAddr) {
log.Debug("Sending spoofed DHCPv6 reply to %s after its %s packet.", core.Bold(target.String()), toType)
log.Debug("Sending spoofed DHCPv6 reply to %s after its %s packet.", tui.Bold(target.String()), toType)
err, reply := s.dhcp6For(dhcp6.MessageTypeReply, req)
if err != nil {
@ -308,9 +309,9 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
}
if h, found := s.Session.Lan.Get(target.String()); found {
log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), h)
log.Info("[%s] IPv6 address %s is now assigned to %s", tui.Green("dhcp6"), addr.String(), h)
} else {
log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), target)
log.Info("[%s] IPv6 address %s is now assigned to %s", tui.Green("dhcp6"), addr.String(), target)
}
} else {
log.Debug("DHCPv6 renew sent to %s", target)

View file

@ -6,7 +6,6 @@ import (
"net"
"sync"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
@ -14,6 +13,8 @@ import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"github.com/evilsocket/islazy/tui"
)
type DNSSpoofer struct {
@ -120,7 +121,7 @@ func (s *DNSSpoofer) Configure() error {
}
for _, entry := range s.Hosts {
log.Info("[%s] %s -> %s", core.Green("dns.spoof"), entry.Host, entry.Address)
log.Info("[%s] %s -> %s", tui.Green("dns.spoof"), entry.Host, entry.Address)
}
if !s.Session.Firewall.IsForwardingEnabled() {
@ -139,7 +140,7 @@ func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *
who = t.String()
}
log.Info("[%s] sending spoofed DNS reply for %s %s to %s.", core.Green("dns"), core.Red(domain), core.Dim(redir), core.Bold(who))
log.Info("[%s] sending spoofed DNS reply for %s %s to %s.", tui.Green("dns"), tui.Red(domain), tui.Dim(redir), tui.Bold(who))
var err error
var src, dst net.IP

View file

@ -8,9 +8,9 @@ import (
"regexp"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/gobwas/glob"
"github.com/evilsocket/islazy/str"
)
var hostsSplitter = regexp.MustCompile(`\s+`)
@ -57,7 +57,7 @@ func HostsFromFile(filename string) (err error, entries []HostEntry) {
scanner := bufio.NewScanner(input)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
line := core.Trim(scanner.Text())
line := str.Trim(scanner.Text())
if line == "" || line[0] == '#' {
continue
}

View file

@ -6,8 +6,9 @@ import (
"strings"
"sync"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/str"
)
var (
@ -32,7 +33,7 @@ func NewIgnoreList() *IgnoreList {
}
func (l *IgnoreList) checkExpression(expr string) (string, error) {
expr = core.Trim(expr)
expr = str.Trim(expr)
if expr == "" {
return "", ErrEmptyExpression
}

View file

@ -6,9 +6,12 @@ import (
"strconv"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/str"
"github.com/evilsocket/islazy/tui"
)
type EventsStream struct {
@ -50,7 +53,7 @@ func NewEventsStream(s *session.Session) *EventsStream {
func(args []string) error {
limit := -1
if len(args) == 1 {
arg := core.Trim(args[0])
arg := str.Trim(args[0])
limit, _ = strconv.Atoi(arg)
}
return stream.Show(limit)
@ -62,7 +65,7 @@ func NewEventsStream(s *session.Session) *EventsStream {
tag := args[0]
timeout := 0
if len(args) == 2 {
t := core.Trim(args[1])
t := str.Trim(args[1])
if t != "" {
n, err := strconv.Atoi(t)
if err != nil {
@ -143,7 +146,7 @@ func (s *EventsStream) Configure() (err error) {
if err, output = s.StringParam("events.stream.output"); err == nil {
if output == "" {
s.output = os.Stdout
} else if output, err = core.ExpandPath(output); err == nil {
} else if output, err = fs.Expand(output); err == nil {
s.output, err = os.OpenFile(output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
}
} else if err, s.dumpHttpReqs = s.BoolParam("events.stream.http.request.dump"); err != nil {
@ -211,9 +214,9 @@ func (s *EventsStream) Show(limit int) error {
func (s *EventsStream) startWaitingFor(tag string, timeout int) error {
if timeout == 0 {
log.Info("waiting for event %s ...", core.Green(tag))
log.Info("waiting for event %s ...", tui.Green(tag))
} else {
log.Info("waiting for event %s for %d seconds ...", core.Green(tag), timeout)
log.Info("waiting for event %s for %d seconds ...", tui.Green(tag), timeout)
go func() {
time.Sleep(time.Duration(timeout) * time.Second)
s.waitFor = ""

View file

@ -5,11 +5,12 @@ import (
"os"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/session"
"github.com/google/go-github/github"
"github.com/evilsocket/islazy/tui"
)
const eventTimeFormat = "15:04:05"
@ -17,7 +18,7 @@ const eventTimeFormat = "15:04:05"
func (s *EventsStream) viewLogEvent(e session.Event) {
fmt.Fprintf(s.output, "[%s] [%s] [%s] %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
e.Label(),
e.Data.(session.LogMessage).Message)
}
@ -37,21 +38,21 @@ func (s *EventsStream) viewWiFiEvent(e session.Event) {
if e.Tag == "wifi.ap.new" {
fmt.Fprintf(s.output, "[%s] [%s] wifi access point %s%s detected as %s%s.\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
core.Bold(ap.ESSID()),
core.Dim(core.Yellow(rssi)),
core.Green(ap.BSSID()),
core.Dim(vend))
tui.Green(e.Tag),
tui.Bold(ap.ESSID()),
tui.Dim(tui.Yellow(rssi)),
tui.Green(ap.BSSID()),
tui.Dim(vend))
} else if e.Tag == "wifi.ap.lost" {
fmt.Fprintf(s.output, "[%s] [%s] wifi access point %s (%s) lost.\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
core.Red(ap.ESSID()),
tui.Green(e.Tag),
tui.Red(ap.ESSID()),
ap.BSSID())
} else {
fmt.Fprintf(s.output, "[%s] [%s] %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
ap.String())
}
} else if e.Tag == "wifi.client.probe" {
@ -69,11 +70,11 @@ func (s *EventsStream) viewWiFiEvent(e session.Event) {
fmt.Fprintf(s.output, "[%s] [%s] station %s%s is probing for SSID %s%s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
probe.FromAddr.String(),
core.Dim(desc),
core.Bold(probe.SSID),
core.Yellow(rssi))
tui.Dim(desc),
tui.Bold(probe.SSID),
tui.Yellow(rssi))
}
}
@ -95,21 +96,21 @@ func (s *EventsStream) viewendpointEvent(e session.Event) {
if e.Tag == "endpoint.new" {
fmt.Fprintf(s.output, "[%s] [%s] endpoint %s%s detected as %s%s.\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
core.Bold(t.IpAddress),
core.Dim(name),
core.Green(t.HwAddress),
core.Dim(vend))
tui.Green(e.Tag),
tui.Bold(t.IpAddress),
tui.Dim(name),
tui.Green(t.HwAddress),
tui.Dim(vend))
} else if e.Tag == "endpoint.lost" {
fmt.Fprintf(s.output, "[%s] [%s] endpoint %s%s lost.\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
core.Red(t.IpAddress),
core.Dim(vend))
tui.Green(e.Tag),
tui.Red(t.IpAddress),
tui.Dim(vend))
} else {
fmt.Fprintf(s.output, "[%s] [%s] %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
t.String())
}
}
@ -117,7 +118,7 @@ func (s *EventsStream) viewendpointEvent(e session.Event) {
func (s *EventsStream) viewModuleEvent(e session.Event) {
fmt.Fprintf(s.output, "[%s] [%s] %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
e.Data)
}
@ -127,7 +128,7 @@ func (s *EventsStream) viewSnifferEvent(e session.Event) {
} else {
fmt.Fprintf(s.output, "[%s] [%s] %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
e.Data.(SnifferEvent).Message)
}
}
@ -136,9 +137,9 @@ func (s *EventsStream) viewSynScanEvent(e session.Event) {
se := e.Data.(SynScanEvent)
fmt.Fprintf(s.output, "[%s] [%s] found open port %d for %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
se.Port,
core.Bold(se.Address))
tui.Bold(se.Address))
}
func (s *EventsStream) viewUpdateEvent(e session.Event) {
@ -146,8 +147,8 @@ func (s *EventsStream) viewUpdateEvent(e session.Event) {
fmt.Fprintf(s.output, "[%s] [%s] an update to version %s is available at %s\n",
e.Time.Format(eventTimeFormat),
core.Bold(core.Yellow(e.Tag)),
core.Bold(*update.TagName),
tui.Bold(tui.Yellow(e.Tag)),
tui.Bold(*update.TagName),
*update.HTMLURL)
}
@ -169,7 +170,7 @@ func (s *EventsStream) View(e session.Event, refresh bool) {
} else if e.Tag == "update.available" {
s.viewUpdateEvent(e)
} else {
fmt.Fprintf(s.output, "[%s] [%s] %v\n", e.Time.Format(eventTimeFormat), core.Green(e.Tag), e)
fmt.Fprintf(s.output, "[%s] [%s] %v\n", e.Time.Format(eventTimeFormat), tui.Green(e.Tag), e)
}
if refresh && s.output == os.Stdout {

View file

@ -6,9 +6,10 @@ package modules
import (
"fmt"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/tui"
)
func (s *EventsStream) viewBLEEvent(e session.Event) {
@ -16,40 +17,40 @@ func (s *EventsStream) viewBLEEvent(e session.Event) {
dev := e.Data.(*network.BLEDevice)
name := dev.Device.Name()
if name != "" {
name = " " + core.Bold(name)
name = " " + tui.Bold(name)
}
vend := dev.Vendor
if vend != "" {
vend = fmt.Sprintf(" (%s)", core.Yellow(vend))
vend = fmt.Sprintf(" (%s)", tui.Yellow(vend))
}
fmt.Fprintf(s.output, "[%s] [%s] new BLE device%s detected as %s%s %s.\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
name,
dev.Device.ID(),
vend,
core.Dim(fmt.Sprintf("%d dBm", dev.RSSI)))
tui.Dim(fmt.Sprintf("%d dBm", dev.RSSI)))
} else if e.Tag == "ble.device.lost" {
dev := e.Data.(*network.BLEDevice)
name := dev.Device.Name()
if name != "" {
name = " " + core.Bold(name)
name = " " + tui.Bold(name)
}
vend := dev.Vendor
if vend != "" {
vend = fmt.Sprintf(" (%s)", core.Yellow(vend))
vend = fmt.Sprintf(" (%s)", tui.Yellow(vend))
}
fmt.Fprintf(s.output, "[%s] [%s] BLE device%s %s%s lost.\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
name,
dev.Device.ID(),
vend)
} /* else {
fmt.Fprintf(s.output,"[%s] [%s]\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag))
tui.Green(e.Tag))
} */
}

View file

@ -10,8 +10,9 @@ import (
"regexp"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/tui"
)
var (
@ -67,20 +68,20 @@ func (s *EventsStream) dumpForm(body []byte) string {
value = parts[1]
}
form = append(form, fmt.Sprintf("%s=%s", core.Green(name), core.Bold(core.Red(value))))
form = append(form, fmt.Sprintf("%s=%s", tui.Green(name), tui.Bold(tui.Red(value))))
} else {
value, err := url.QueryUnescape(v)
if err != nil {
value = v
}
form = append(form, fmt.Sprintf("%s", core.Bold(core.Red(value))))
form = append(form, fmt.Sprintf("%s", tui.Bold(tui.Red(value))))
}
}
return "\n" + strings.Join(form, "&") + "\n"
}
func (s *EventsStream) dumpText(body []byte) string {
return "\n" + core.Bold(core.Red(string(body))) + "\n"
return "\n" + tui.Bold(tui.Red(string(body))) + "\n"
}
func (s *EventsStream) dumpGZIP(body []byte) string {
@ -105,7 +106,7 @@ func (s *EventsStream) dumpJSON(body []byte) string {
pretty = string(buf.Bytes())
}
return "\n" + reJsonKey.ReplaceAllString(pretty, core.W(core.GREEN, `$1:`)) + "\n"
return "\n" + reJsonKey.ReplaceAllString(pretty, tui.Green(`$1:`)) + "\n"
}
func (s *EventsStream) dumpXML(body []byte) string {
@ -123,15 +124,15 @@ func (s *EventsStream) viewHttpRequest(e session.Event) {
fmt.Fprintf(s.output, "[%s] [%s] %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
se.Message)
if s.shouldDumpHttpRequest(req) {
dump := fmt.Sprintf("%s %s %s\n", core.Bold(req.Method), req.URL, core.Dim(req.Proto))
dump += fmt.Sprintf("%s: %s\n", core.Blue("Host"), core.Yellow(req.Host))
dump := fmt.Sprintf("%s %s %s\n", tui.Bold(req.Method), req.URL, tui.Dim(req.Proto))
dump += fmt.Sprintf("%s: %s\n", tui.Blue("Host"), tui.Yellow(req.Host))
for name, values := range req.Headers {
for _, value := range values {
dump += fmt.Sprintf("%s: %s\n", core.Blue(name), core.Yellow(value))
dump += fmt.Sprintf("%s: %s\n", tui.Blue(name), tui.Yellow(value))
}
}
@ -161,14 +162,14 @@ func (s *EventsStream) viewHttpResponse(e session.Event) {
fmt.Fprintf(s.output, "[%s] [%s] %s\n",
e.Time.Format(eventTimeFormat),
core.Green(e.Tag),
tui.Green(e.Tag),
se.Message)
if s.shouldDumpHttpResponse(res) {
dump := fmt.Sprintf("%s %s\n", core.Dim(res.Protocol), res.Status)
dump := fmt.Sprintf("%s %s\n", tui.Dim(res.Protocol), res.Status)
for name, values := range res.Headers {
for _, value := range values {
dump += fmt.Sprintf("%s: %s\n", core.Blue(name), core.Yellow(value))
dump += fmt.Sprintf("%s: %s\n", tui.Blue(name), tui.Yellow(value))
}
}

View file

@ -5,12 +5,13 @@ import (
"io"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/adrianmo/go-nmea"
"github.com/tarm/serial"
"github.com/evilsocket/islazy/str"
)
type GPS struct {
@ -97,7 +98,7 @@ func (gps *GPS) readLine() (line string, err error) {
return
} else if n == 1 {
if b[0] == '\n' {
return core.Trim(line), nil
return str.Trim(line), nil
} else {
line += string(b[0])
}

View file

@ -15,7 +15,6 @@ import (
"strings"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/firewall"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
@ -23,6 +22,9 @@ import (
"github.com/elazarl/goproxy"
"github.com/inconshreveable/go-vhost"
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/tui"
)
const (
@ -116,7 +118,7 @@ func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scrip
if strings.HasPrefix(jsToInject, "http://") || strings.HasPrefix(jsToInject, "https://") {
p.jsHook = fmt.Sprintf("<script src=\"%s\" type=\"text/javascript\"></script></head>", jsToInject)
} else if core.Exists(jsToInject) {
} else if fs.Exists(jsToInject) {
if data, err := ioutil.ReadFile(jsToInject); err != nil {
return err
} else {
@ -187,7 +189,7 @@ func TLSConfigFromCA(ca *tls.Certificate) func(host string, ctx *goproxy.ProxyCt
cert := getCachedCert(hostname, port)
if cert == nil {
log.Debug("Creating spoofed certificate for %s:%d", core.Yellow(hostname), port)
log.Debug("Creating spoofed certificate for %s:%d", tui.Yellow(hostname), port)
cert, err = btls.SignCertificateForHost(ca, hostname, port)
if err != nil {
log.Warning("Cannot sign host certificate with provided CA: %s", err)
@ -298,7 +300,7 @@ func (p *HTTPProxy) httpsWorker() error {
return
}
log.Debug("[%s] proxying connection from %s to %s", core.Green("https.proxy"), core.Bold(stripPort(c.RemoteAddr().String())), core.Yellow(hostname))
log.Debug("[%s] proxying connection from %s to %s", tui.Green("https.proxy"), tui.Bold(stripPort(c.RemoteAddr().String())), tui.Yellow(hostname))
req := &http.Request{
Method: "CONNECT",
@ -320,12 +322,12 @@ func (p *HTTPProxy) Start() {
go func() {
var err error
strip := core.Yellow("enabled")
strip := tui.Yellow("enabled")
if !p.stripper.Enabled() {
strip = core.Dim("disabled")
strip = tui.Dim("disabled")
}
log.Info("%s started on %s (sslstrip %s)", core.Green(p.Name), p.Server.Addr, strip)
log.Info("%s started on %s (sslstrip %s)", tui.Green(p.Name), p.Server.Addr, strip)
if p.isTLS {
err = p.httpsWorker()

View file

@ -5,10 +5,11 @@ import (
"net/http"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/elazarl/goproxy"
"github.com/evilsocket/islazy/tui"
)
func (p *HTTPProxy) fixRequestHeaders(req *http.Request) {
@ -20,7 +21,7 @@ func (p *HTTPProxy) fixRequestHeaders(req *http.Request) {
}
func (p *HTTPProxy) onRequestFilter(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
log.Debug("(%s) < %s %s %s%s", core.Green(p.Name), req.RemoteAddr, req.Method, req.Host, req.URL.Path)
log.Debug("(%s) < %s %s %s%s", tui.Green(p.Name), req.RemoteAddr, req.Method, req.Host, req.URL.Path)
p.fixRequestHeaders(req)
@ -99,11 +100,11 @@ func (p *HTTPProxy) doScriptInjection(res *http.Response, cType string) (error,
return err, nil
} else if html := string(raw); strings.Contains(html, "</head>") {
log.Info("(%s) > injecting javascript (%d bytes) into %s (%d bytes) for %s",
core.Green(p.Name),
tui.Green(p.Name),
len(p.jsHook),
core.Yellow(res.Request.Host+res.Request.URL.Path),
tui.Yellow(res.Request.Host+res.Request.URL.Path),
len(raw),
core.Bold(strings.Split(res.Request.RemoteAddr, ":")[0]))
tui.Bold(strings.Split(res.Request.RemoteAddr, ":")[0]))
html = strings.Replace(html, "</head>", p.jsHook, -1)
newResp := goproxy.NewResponse(res.Request, cType, res.StatusCode, html)
@ -125,7 +126,7 @@ func (p *HTTPProxy) onResponseFilter(res *http.Response, ctx *goproxy.ProxyCtx)
return nil
}
log.Debug("(%s) > %s %s %s%s", core.Green(p.Name), res.Request.RemoteAddr, res.Request.Method, res.Request.Host, res.Request.URL.Path)
log.Debug("(%s) > %s %s %s%s", tui.Green(p.Name), res.Request.RemoteAddr, res.Request.Method, res.Request.Host, res.Request.URL.Path)
p.fixResponseHeaders(res)

View file

@ -9,7 +9,6 @@ import (
"regexp"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
@ -18,6 +17,8 @@ import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"github.com/evilsocket/islazy/tui"
)
var (
@ -66,7 +67,7 @@ func (s *SSLStripper) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp
who = t.String()
}
log.Debug("[%s] Sending spoofed DNS reply for %s %s to %s.", core.Green("dns"), core.Red(domain), core.Dim(redir), core.Bold(who))
log.Debug("[%s] Sending spoofed DNS reply for %s %s to %s.", tui.Green("dns"), tui.Red(domain), tui.Dim(redir), tui.Bold(who))
var err error
var src, dst net.IP
@ -245,7 +246,7 @@ func (s *SSLStripper) Preprocess(req *http.Request, ctx *goproxy.ProxyCtx) (redi
// handle stripped domains
original := s.hosts.Unstrip(req.Host)
if original != nil {
log.Info("[%s] Replacing host %s with %s in request from %s", core.Green("sslstrip"), core.Bold(req.Host), core.Yellow(original.Hostname), req.RemoteAddr)
log.Info("[%s] Replacing host %s with %s in request from %s", tui.Green("sslstrip"), tui.Bold(req.Host), tui.Yellow(original.Hostname), req.RemoteAddr)
req.Host = original.Hostname
req.URL.Host = original.Hostname
req.Header.Set("Host", original.Hostname)
@ -254,7 +255,7 @@ func (s *SSLStripper) Preprocess(req *http.Request, ctx *goproxy.ProxyCtx) (redi
if !s.cookies.IsClean(req) {
// check if we need to redirect the user in order
// to make unknown session cookies expire
log.Info("[%s] Sending expired cookies for %s to %s", core.Green("sslstrip"), core.Yellow(req.Host), req.RemoteAddr)
log.Info("[%s] Sending expired cookies for %s to %s", tui.Green("sslstrip"), tui.Yellow(req.Host), req.RemoteAddr)
s.cookies.Track(req)
redir = s.cookies.Expire(req)
}
@ -267,7 +268,7 @@ func (s *SSLStripper) isMaxRedirs(hostname string) bool {
if nredirs, found := s.redirs[hostname]; found {
// reached the threshold?
if nredirs >= maxRedirs {
log.Warning("[%s] Hit max redirections for %s, serving HTTPS.", core.Green("sslstrip"), hostname)
log.Warning("[%s] Hit max redirections for %s, serving HTTPS.", tui.Green("sslstrip"), hostname)
// reset
delete(s.redirs, hostname)
return true
@ -299,7 +300,7 @@ func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) {
// are we getting redirected from http to https?
if orig.Scheme == "http" && location.Scheme == "https" {
log.Info("[%s] Got redirection from HTTPS to HTTP: %s -> %s", core.Green("sslstrip"), core.Yellow("http://"+origHost), core.Bold("https://"+newHost))
log.Info("[%s] Got redirection from HTTPS to HTTP: %s -> %s", tui.Green("sslstrip"), tui.Yellow("http://"+origHost), tui.Bold("https://"+newHost))
// if we still did not reach max redirections, strip the URL down to
// an alternative HTTP version
@ -342,11 +343,11 @@ func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) {
if nurls == 1 {
plural = ""
}
log.Info("[%s] Stripping %d SSL link%s from %s", core.Green("sslstrip"), nurls, plural, core.Bold(res.Request.Host))
log.Info("[%s] Stripping %d SSL link%s from %s", tui.Green("sslstrip"), nurls, plural, tui.Bold(res.Request.Host))
}
for url, stripped := range urls {
log.Debug("Stripping url %s to %s", core.Bold(url), core.Yellow(stripped))
log.Debug("Stripping url %s to %s", tui.Bold(url), tui.Yellow(stripped))
body = strings.Replace(body, url, stripped, -1)

View file

@ -7,10 +7,12 @@ import (
"strings"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/bettercap/bettercap/tls"
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/tui"
)
type HttpServer struct {
@ -103,7 +105,7 @@ func (httpd *HttpServer) Configure() error {
fileServer := http.FileServer(http.Dir(path))
router.HandleFunc("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Info("(%s) %s %s %s%s", core.Green("httpd"), core.Bold(strings.Split(r.RemoteAddr, ":")[0]), r.Method, r.Host, r.URL.Path)
log.Info("(%s) %s %s %s%s", tui.Green("httpd"), tui.Bold(strings.Split(r.RemoteAddr, ":")[0]), r.Method, r.Host, r.URL.Path)
fileServer.ServeHTTP(w, r)
}))
@ -121,18 +123,18 @@ func (httpd *HttpServer) Configure() error {
if err, certFile = httpd.StringParam("http.server.certificate"); err != nil {
return err
} else if certFile, err = core.ExpandPath(certFile); err != nil {
} else if certFile, err = fs.Expand(certFile); err != nil {
return err
}
if err, keyFile = httpd.StringParam("http.server.key"); err != nil {
return err
} else if keyFile, err = core.ExpandPath(keyFile); err != nil {
} else if keyFile, err = fs.Expand(keyFile); err != nil {
return err
}
if certFile != "" && keyFile != "" {
if !core.Exists(certFile) || !core.Exists(keyFile) {
if !fs.Exists(certFile) || !fs.Exists(keyFile) {
err, cfg := tls.CertConfigFromModule("http.server", httpd.SessionModule)
if err != nil {
return err

View file

@ -1,10 +1,11 @@
package modules
import (
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/bettercap/bettercap/tls"
"github.com/evilsocket/islazy/fs"
)
type HttpsProxy struct {
@ -107,11 +108,11 @@ func (p *HttpsProxy) Configure() error {
return err
} else if err, certFile = p.StringParam("https.proxy.certificate"); err != nil {
return err
} else if certFile, err = core.ExpandPath(certFile); err != nil {
} else if certFile, err = fs.Expand(certFile); err != nil {
return err
} else if err, keyFile = p.StringParam("https.proxy.key"); err != nil {
return err
} else if keyFile, err = core.ExpandPath(keyFile); err != nil {
} else if keyFile, err = fs.Expand(keyFile); err != nil {
return err
} else if err, scriptPath = p.StringParam("https.proxy.script"); err != nil {
return err
@ -119,7 +120,7 @@ func (p *HttpsProxy) Configure() error {
return err
}
if !core.Exists(certFile) || !core.Exists(keyFile) {
if !fs.Exists(certFile) || !fs.Exists(keyFile) {
err, cfg := tls.CertConfigFromModule("https.proxy", p.SessionModule)
if err != nil {
return err

View file

@ -10,6 +10,8 @@ import (
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/tui"
)
type MacChanger struct {
@ -110,14 +112,14 @@ func (mc *MacChanger) Start() error {
}
return mc.SetRunning(true, func() {
log.Info("Interface mac address set to %s", core.Bold(mc.fakeMac.String()))
log.Info("Interface mac address set to %s", tui.Bold(mc.fakeMac.String()))
})
}
func (mc *MacChanger) Stop() error {
return mc.SetRunning(false, func() {
if err := mc.setMac(mc.originalMac); err == nil {
log.Info("Interface mac address restored to %s", core.Bold(mc.originalMac.String()))
log.Info("Interface mac address restored to %s", tui.Bold(mc.originalMac.String()))
} else {
log.Error("Error while restoring mac address: %s", err)
}

View file

@ -8,10 +8,11 @@ import (
"net"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/tui"
)
type MySQLServer struct {
@ -103,10 +104,10 @@ func (mysql *MySQLServer) Start() error {
}
return mysql.SetRunning(true, func() {
log.Info("[%s] server starting on address %s", core.Green("mysql.server"), mysql.address)
log.Info("[%s] server starting on address %s", tui.Green("mysql.server"), mysql.address)
for mysql.Running() {
if conn, err := mysql.listener.AcceptTCP(); err != nil {
log.Warning("[%s] error while accepting tcp connection: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while accepting tcp connection: %s", tui.Green("mysql.server"), err)
continue
} else {
defer conn.Close()
@ -117,13 +118,13 @@ func (mysql *MySQLServer) Start() error {
reader := bufio.NewReader(conn)
read := 0
log.Info("[%s] connection from %s", core.Green("mysql.server"), clientAddress)
log.Info("[%s] connection from %s", tui.Green("mysql.server"), clientAddress)
if _, err := conn.Write(packets.MySQLGreeting); err != nil {
log.Warning("[%s] error while writing server greeting: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while writing server greeting: %s", tui.Green("mysql.server"), err)
continue
} else if read, err = reader.Read(readBuffer); err != nil {
log.Warning("[%s] error while reading client message: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while reading client message: %s", tui.Green("mysql.server"), err)
continue
}
@ -134,38 +135,38 @@ func (mysql *MySQLServer) Start() error {
loadData := string(capabilities[8])
username := string(bytes.Split(readBuffer[36:], []byte{0})[0])
log.Info("[%s] can use LOAD DATA LOCAL: %s", core.Green("mysql.server"), loadData)
log.Info("[%s] login request username: %s", core.Green("mysql.server"), core.Bold(username))
log.Info("[%s] can use LOAD DATA LOCAL: %s", tui.Green("mysql.server"), loadData)
log.Info("[%s] login request username: %s", tui.Green("mysql.server"), tui.Bold(username))
if _, err := conn.Write(packets.MySQLFirstResponseOK); err != nil {
log.Warning("[%s] error while writing server first response ok: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while writing server first response ok: %s", tui.Green("mysql.server"), err)
continue
} else if _, err := reader.Read(readBuffer); err != nil {
log.Warning("[%s] error while reading client message: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while reading client message: %s", tui.Green("mysql.server"), err)
continue
} else if _, err := conn.Write(packets.MySQLGetFile(mysql.infile)); err != nil {
log.Warning("[%s] error while writing server get file request: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while writing server get file request: %s", tui.Green("mysql.server"), err)
continue
} else if read, err = reader.Read(readBuffer); err != nil {
log.Warning("[%s] error while readind buffer: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while readind buffer: %s", tui.Green("mysql.server"), err)
continue
}
if strings.HasPrefix(mysql.infile, "\\") {
log.Info("[%s] NTLM from '%s' relayed to %s", core.Green("mysql.server"), clientAddress, mysql.infile)
log.Info("[%s] NTLM from '%s' relayed to %s", tui.Green("mysql.server"), clientAddress, mysql.infile)
} else if fileSize := read - 9; fileSize < 4 {
log.Warning("[%s] unpexpected buffer size %d", core.Green("mysql.server"), read)
log.Warning("[%s] unpexpected buffer size %d", tui.Green("mysql.server"), read)
} else {
log.Info("[%s] read file ( %s ) is %d bytes", core.Green("mysql.server"), mysql.infile, fileSize)
log.Info("[%s] read file ( %s ) is %d bytes", tui.Green("mysql.server"), mysql.infile, fileSize)
fileData := readBuffer[4 : read-4]
if mysql.outfile == "" {
log.Info("\n%s", string(fileData))
} else {
log.Info("[%s] saving to %s ...", core.Green("mysql.server"), mysql.outfile)
log.Info("[%s] saving to %s ...", tui.Green("mysql.server"), mysql.outfile)
if err := ioutil.WriteFile(mysql.outfile, fileData, 0755); err != nil {
log.Warning("[%s] error while saving the file: %s", core.Green("mysql.server"), err)
log.Warning("[%s] error while saving the file: %s", tui.Green("mysql.server"), err)
}
}
}

View file

@ -6,11 +6,12 @@ import (
"sort"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
"github.com/dustin/go-humanize"
"github.com/evilsocket/islazy/tui"
)
var (
@ -38,12 +39,12 @@ func (d *Discovery) getRow(e *network.Endpoint, withMeta bool) [][]string {
mac := e.HwAddress
if d.Session.Lan.WasMissed(e.HwAddress) {
// if endpoint was not found in ARP at least once
addr = core.Dim(addr)
mac = core.Dim(mac)
addr = tui.Dim(addr)
mac = tui.Dim(mac)
} else if sinceStarted > (justJoinedTimeInterval*2) && sinceFirstSeen <= justJoinedTimeInterval {
// if endpoint was first seen in the last 10 seconds
addr = core.Bold(addr)
mac = core.Bold(mac)
addr = tui.Bold(addr)
mac = tui.Bold(mac)
}
name := ""
@ -52,9 +53,9 @@ func (d *Discovery) getRow(e *network.Endpoint, withMeta bool) [][]string {
} else if e == d.Session.Gateway {
name = "gateway"
} else if e.Alias != "" {
name = core.Green(e.Alias)
name = tui.Green(e.Alias)
} else if e.Hostname != "" {
name = core.Yellow(e.Hostname)
name = tui.Yellow(e.Hostname)
}
var traffic *packets.Traffic
@ -67,19 +68,19 @@ func (d *Discovery) getRow(e *network.Endpoint, withMeta bool) [][]string {
sinceLastSeen := time.Since(e.LastSeen)
if sinceStarted > aliveTimeInterval && sinceLastSeen <= aliveTimeInterval {
// if endpoint seen in the last 10 seconds
seen = core.Bold(seen)
seen = tui.Bold(seen)
} else if sinceLastSeen <= presentTimeInterval {
// if endpoint seen in the last 60 seconds
} else {
// not seen in a while
seen = core.Dim(seen)
seen = tui.Dim(seen)
}
row := []string{
addr,
mac,
name,
core.Dim(e.Vendor),
tui.Dim(e.Vendor),
humanize.Bytes(traffic.Sent),
humanize.Bytes(traffic.Received),
seen,
@ -88,12 +89,12 @@ func (d *Discovery) getRow(e *network.Endpoint, withMeta bool) [][]string {
if !withMeta {
return [][]string{row}
} else if e.Meta.Empty() {
return [][]string{append(row, core.Dim("-"))}
return [][]string{append(row, tui.Dim("-"))}
}
metas := []string{}
e.Meta.Each(func(name string, value interface{}) {
metas = append(metas, fmt.Sprintf("%s:%s", core.Green(name), core.Yellow(value.(string))))
metas = append(metas, fmt.Sprintf("%s:%s", tui.Green(name), tui.Yellow(value.(string))))
})
sort.Strings(metas)
@ -164,13 +165,13 @@ func (d *Discovery) Show(by string, expr string) (err error) {
}
}
core.AsTable(os.Stdout, colNames, rows)
tui.Table(os.Stdout, colNames, rows)
d.Session.Queue.Stats.RLock()
fmt.Printf("\n%s %s / %s %s / %d pkts / %d errs\n\n",
core.Red("↑"),
tui.Red("↑"),
humanize.Bytes(d.Session.Queue.Stats.Sent),
core.Green("↓"),
tui.Green("↓"),
humanize.Bytes(d.Session.Queue.Stats.Received),
d.Session.Queue.Stats.PktReceived,
d.Session.Queue.Stats.Errors)

View file

@ -4,12 +4,13 @@ import (
"os"
"regexp"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/google/gopacket/pcap"
"github.com/google/gopacket/pcapgo"
"github.com/evilsocket/islazy/tui"
)
type SnifferContext struct {
@ -98,8 +99,8 @@ func NewSnifferContext() *SnifferContext {
}
var (
no = core.Red("no")
yes = core.Green("yes")
no = tui.Red("no")
yes = tui.Green("yes")
yn = map[bool]string{
true: yes,
false: no,
@ -109,9 +110,9 @@ var (
func (c *SnifferContext) Log(sess *session.Session) {
log.Info("Skip local packets : %s", yn[c.DumpLocal])
log.Info("Verbose : %s", yn[c.Verbose])
log.Info("BPF Filter : '%s'", core.Yellow(c.Filter))
log.Info("Regular expression : '%s'", core.Yellow(c.Expression))
log.Info("File output : '%s'", core.Yellow(c.Output))
log.Info("BPF Filter : '%s'", tui.Yellow(c.Filter))
log.Info("Regular expression : '%s'", tui.Yellow(c.Expression))
log.Info("File output : '%s'", tui.Yellow(c.Output))
}
func (c *SnifferContext) Close() {

View file

@ -3,10 +3,10 @@ package modules
import (
"strings"
"github.com/bettercap/bettercap/core"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
@ -41,11 +41,11 @@ func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
ip.DstIP.String(),
nil,
"%s %s > %s : %s is %s",
core.W(core.BG_DGRAY+core.FG_WHITE, "dns"),
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "dns"),
vIP(ip.SrcIP),
vIP(ip.DstIP),
core.Yellow(hostname),
core.Dim(strings.Join(ips, ", ")),
tui.Yellow(hostname),
tui.Dim(strings.Join(ips, ", ")),
).Push()
}

View file

@ -8,12 +8,12 @@ import (
"net/http"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/dustin/go-humanize"
"github.com/evilsocket/islazy/tui"
)
type HTTPRequest struct {
@ -126,10 +126,10 @@ func httpParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
req.Host,
toSerializableRequest(req),
"%s %s %s %s%s",
core.W(core.BG_RED+core.FG_BLACK, "http"),
tui.Wrap(tui.BACKRED+tui.FOREBLACK, "http"),
vIP(ip.SrcIP),
core.W(core.BG_LBLUE+core.FG_BLACK, req.Method),
core.Yellow(req.Host),
tui.Wrap(tui.BACKLIGHTBLUE+tui.FOREBLACK, req.Method),
tui.Yellow(req.Host),
vURL(req.URL.String()),
).Push()
@ -143,13 +143,13 @@ func httpParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
ip.DstIP.String(),
sres,
"%s %s:%d %s -> %s (%s %s)",
core.W(core.BG_RED+core.FG_BLACK, "http"),
tui.Wrap(tui.BACKRED+tui.FOREBLACK, "http"),
vIP(ip.SrcIP),
tcp.SrcPort,
core.Bold(res.Status),
tui.Bold(res.Status),
vIP(ip.DstIP),
core.Dim(humanize.Bytes(uint64(len(sres.Body)))),
core.Yellow(sres.ContentType),
tui.Dim(humanize.Bytes(uint64(len(sres.Body)))),
tui.Yellow(sres.ContentType),
).Push()
return true

View file

@ -3,11 +3,12 @@ package modules
import (
"encoding/asn1"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/packets"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
func krb5Parser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
@ -29,7 +30,7 @@ func krb5Parser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
ip.DstIP.String(),
nil,
"%s %s -> %s : %s",
core.W(core.BG_RED+core.FG_BLACK, "krb-as-req"),
tui.Wrap(tui.BACKRED+tui.FOREBLACK, "krb-as-req"),
vIP(ip.SrcIP),
vIP(ip.DstIP),
s,

View file

@ -3,11 +3,12 @@ package modules
import (
"strings"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/packets"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
func mdnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
@ -22,10 +23,10 @@ func mdnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
ip.DstIP.String(),
nil,
"%s %s : %s query for %s",
core.W(core.BG_DGRAY+core.FG_WHITE, "mdns"),
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "mdns"),
vIP(ip.SrcIP),
core.Dim(q.Type.String()),
core.Yellow(string(q.Name)),
tui.Dim(q.Type.String()),
tui.Yellow(string(q.Name)),
).Push()
}
@ -50,10 +51,10 @@ func mdnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
ip.DstIP.String(),
nil,
"%s %s : %s is %s",
core.W(core.BG_DGRAY+core.FG_WHITE, "mdns"),
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "mdns"),
vIP(ip.SrcIP),
core.Yellow(hostname),
core.Dim(strings.Join(ips, ", ")),
tui.Yellow(hostname),
tui.Dim(strings.Join(ips, ", ")),
).Push()
}

View file

@ -4,11 +4,12 @@ import (
"regexp"
"strings"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/packets"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
var (
@ -53,7 +54,7 @@ func ntlmParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
ip.DstIP.String(),
nil,
"%s %s > %s | %s",
core.W(core.BG_DGRAY+core.FG_WHITE, "ntlm.response"),
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "ntlm.response"),
vIP(ip.SrcIP),
vIP(ip.DstIP),
data.LcString(),

View file

@ -3,12 +3,13 @@ package modules
import (
"fmt"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/packets"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
func tcpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) {
@ -30,12 +31,12 @@ func tcpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) {
"Size": len(ip.Payload),
},
"%s %s:%s > %s:%s %s",
core.W(core.BG_LBLUE+core.FG_BLACK, "tcp"),
tui.Wrap(tui.BACKLIGHTBLUE+tui.FOREBLACK, "tcp"),
vIP(ip.SrcIP),
vPort(tcp.SrcPort),
vIP(ip.DstIP),
vPort(tcp.DstPort),
core.Dim(fmt.Sprintf("%d bytes", len(ip.Payload))),
tui.Dim(fmt.Sprintf("%d bytes", len(ip.Payload))),
).Push()
}
}
@ -61,12 +62,12 @@ func udpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) {
"Size": len(ip.Payload),
},
"%s %s:%s > %s:%s %s",
core.W(core.BG_DGRAY+core.FG_WHITE, "udp"),
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, "udp"),
vIP(ip.SrcIP),
vPort(udp.SrcPort),
vIP(ip.DstIP),
vPort(udp.DstPort),
core.Dim(fmt.Sprintf("%d bytes", len(ip.Payload))),
tui.Dim(fmt.Sprintf("%d bytes", len(ip.Payload))),
).Push()
}
}
@ -82,10 +83,10 @@ func unkParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) {
"Size": len(ip.Payload),
},
"%s %s > %s %s",
core.W(core.BG_DGRAY+core.FG_WHITE, pkt.TransportLayer().LayerType().String()),
tui.Wrap(tui.BACKDARKGRAY+tui.FOREWHITE, pkt.TransportLayer().LayerType().String()),
vIP(ip.SrcIP),
vIP(ip.DstIP),
core.Dim(fmt.Sprintf("%d bytes", len(ip.Payload))),
tui.Dim(fmt.Sprintf("%d bytes", len(ip.Payload))),
).Push()
}
}

View file

@ -3,11 +3,12 @@ package modules
import (
"fmt"
"github.com/bettercap/bettercap/core"
"regexp"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/tui"
)
// poor man's TLS Client Hello with SNI extension parser :P
@ -38,9 +39,9 @@ func sniParser(ip *layers.IPv4, pkt gopacket.Packet, tcp *layers.TCP) bool {
domain,
nil,
"%s %s > %s",
core.W(core.BG_YELLOW+core.FG_WHITE, "sni"),
tui.Wrap(tui.BACKYELLOW+tui.FOREWHITE, "sni"),
vIP(ip.SrcIP),
core.Yellow("https://"+domain),
tui.Yellow("https://"+domain),
).Push()
return true

View file

@ -3,18 +3,20 @@ package modules
import (
"fmt"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/packets"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/str"
"github.com/evilsocket/islazy/tui"
)
func upnpParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
if data := packets.UPNPGetMeta(pkt); data != nil && len(data) > 0 {
s := ""
for name, value := range data {
s += fmt.Sprintf("%s:%s ", core.Blue(name), core.Yellow(value))
s += fmt.Sprintf("%s:%s ", tui.Blue(name), tui.Yellow(value))
}
NewSnifferEvent(
@ -24,10 +26,10 @@ func upnpParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
ip.DstIP.String(),
nil,
"%s %s -> %s : %s",
core.W(core.BG_RED+core.FG_BLACK, "upnp"),
tui.Wrap(tui.BACKRED+tui.FOREBLACK, "upnp"),
vIP(ip.SrcIP),
vIP(ip.DstIP),
core.Trim(s),
str.Trim(s),
).Push()
return true

View file

@ -4,15 +4,15 @@ import (
"fmt"
"net"
"github.com/google/gopacket/layers"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/tui"
"github.com/google/gopacket/layers"
)
func vIP(ip net.IP) string {
if session.I.Interface.IP.Equal(ip) {
return core.Dim("local")
return tui.Dim("local")
} else if session.I.Gateway.IP.Equal(ip) {
return "gateway"
}
@ -32,11 +32,11 @@ func vPort(p interface{}) string {
sp := fmt.Sprintf("%d", p)
if tcp, ok := p.(layers.TCPPort); ok {
if name, found := layers.TCPPortNames[tcp]; found {
sp = core.Yellow(name)
sp = tui.Yellow(name)
}
} else if udp, ok := p.(layers.UDPPort); ok {
if name, found := layers.UDPPortNames[udp]; found {
sp = core.Yellow(name)
sp = tui.Yellow(name)
}
}

View file

@ -13,6 +13,9 @@ import (
"github.com/bettercap/bettercap/session"
"github.com/chifflier/nfqueue-go/nfqueue"
"github.com/evilsocket/islazy/fs"
"github.com/evilsocket/islazy/tui"
)
type PacketProxy struct {
@ -141,8 +144,8 @@ func (pp *PacketProxy) Configure() (err error) {
}
if pp.pluginPath == "" {
return fmt.Errorf("The parameter %s can not be empty.", core.Bold("packet.proxy.plugin"))
} else if !core.Exists(pp.pluginPath) {
return fmt.Errorf("The parameter %s can not be empty.", tui.Bold("packet.proxy.plugin"))
} else if !fs.Exists(pp.pluginPath) {
return fmt.Errorf("%s does not exist.", pp.pluginPath)
}
@ -194,7 +197,7 @@ func (pp *PacketProxy) Start() error {
}
return pp.SetRunning(true, func() {
log.Info("%s started on queue number %d", core.Green("packet.proxy"), pp.queueNum)
log.Info("%s started on queue number %d", tui.Green("packet.proxy"), pp.queueNum)
defer pp.destroyQueue()

View file

@ -7,7 +7,6 @@ import (
"sync"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
@ -17,6 +16,8 @@ import (
"github.com/google/gopacket/layers"
"github.com/malfunkt/iprange"
"github.com/evilsocket/islazy/str"
)
const synSourcePort = 666
@ -55,8 +56,8 @@ func NewSynScanner(s *session.Session) *SynScanner {
ss.startPort = 1
ss.endPort = 65535
if argc > 1 && core.Trim(args[1]) != "" {
if ss.startPort, err = strconv.Atoi(core.Trim(args[1])); err != nil {
if argc > 1 && str.Trim(args[1]) != "" {
if ss.startPort, err = strconv.Atoi(str.Trim(args[1])); err != nil {
return fmt.Errorf("Invalid START-PORT: %s", err)
}
@ -66,8 +67,8 @@ func NewSynScanner(s *session.Session) *SynScanner {
ss.endPort = ss.startPort
}
if argc > 2 && core.Trim(args[2]) != "" {
if ss.endPort, err = strconv.Atoi(core.Trim(args[2])); err != nil {
if argc > 2 && str.Trim(args[2]) != "" {
if ss.endPort, err = strconv.Atoi(str.Trim(args[2])); err != nil {
return fmt.Errorf("Invalid END-PORT: %s", err)
}
}

View file

@ -11,6 +11,8 @@ import (
"github.com/bettercap/bettercap/session"
"github.com/google/go-github/github"
"github.com/evilsocket/islazy/tui"
)
type UpdateModule struct {
@ -87,7 +89,7 @@ func (u *UpdateModule) Start() error {
if u.versionToNum(core.Version) < u.versionToNum(*latest.TagName) {
u.Session.Events.Add("update.available", latest)
} else {
log.Info("you are running %s which is the latest stable version.", core.Bold(core.Version))
log.Info("you are running %s which is the latest stable version.", tui.Bold(core.Version))
}
} else {
log.Error("error while fetching latest release info from GitHub: %s", err)

View file

@ -8,7 +8,6 @@ import (
"sync"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
@ -17,6 +16,8 @@ import (
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
"github.com/google/gopacket/pcap"
"github.com/evilsocket/islazy/tui"
)
type WiFiModule struct {
@ -209,7 +210,7 @@ func (w *WiFiModule) Configure() error {
defer ihandle.CleanUp()
if err = ihandle.SetRFMon(true); err != nil {
return fmt.Errorf("Error while setting interface %s in monitor mode: %s", core.Bold(w.Session.Interface.Name()), err)
return fmt.Errorf("Error while setting interface %s in monitor mode: %s", tui.Bold(w.Session.Interface.Name()), err)
} else if err = ihandle.SetSnapLen(65536); err != nil {
return err
} else if err = ihandle.SetTimeout(pcap.BlockForever); err != nil {

View file

@ -5,11 +5,12 @@ import (
"net"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
"github.com/evilsocket/islazy/tui"
)
var errNoRecon = errors.New("Module wifi.ap requires module wifi.recon to be activated.")
@ -44,12 +45,12 @@ func (w *WiFiModule) startAp() error {
w.apRunning = false
}()
enc := core.Yellow("WPA2")
enc := tui.Yellow("WPA2")
if !w.apConfig.Encryption {
enc = core.Green("Open")
enc = tui.Green("Open")
}
log.Info("Sending beacons as SSID %s (%s) on channel %d (%s).",
core.Bold(w.apConfig.SSID),
tui.Bold(w.apConfig.SSID),
w.apConfig.BSSID.String(),
w.apConfig.Channel,
enc)

View file

@ -7,10 +7,11 @@ import (
"strconv"
"time"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/network"
"github.com/dustin/go-humanize"
"github.com/evilsocket/islazy/tui"
)
func (w *WiFiModule) isApSelected() bool {
@ -25,22 +26,22 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
bssid := station.HwAddress
if sinceStarted > (justJoinedTimeInterval*2) && sinceFirstSeen <= justJoinedTimeInterval {
// if endpoint was first seen in the last 10 seconds
bssid = core.Bold(bssid)
bssid = tui.Bold(bssid)
}
seen := station.LastSeen.Format("15:04:05")
sinceLastSeen := time.Since(station.LastSeen)
if sinceStarted > aliveTimeInterval && sinceLastSeen <= aliveTimeInterval {
// if endpoint seen in the last 10 seconds
seen = core.Bold(seen)
seen = tui.Bold(seen)
} else if sinceLastSeen > presentTimeInterval {
// if endpoint not seen in the last 60 seconds
seen = core.Dim(seen)
seen = tui.Dim(seen)
}
ssid := station.ESSID()
if ssid == "<hidden>" {
ssid = core.Dim(ssid)
ssid = tui.Dim(ssid)
}
encryption := station.Encryption
@ -48,9 +49,9 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
encryption = fmt.Sprintf("%s (%s, %s)", station.Encryption, station.Cipher, station.Authentication)
}
if encryption == "OPEN" || encryption == "" {
encryption = core.Green("OPEN")
ssid = core.Green(ssid)
bssid = core.Green(bssid)
encryption = tui.Green("OPEN")
ssid = tui.Green(ssid)
bssid = tui.Green(bssid)
}
sent := ""
if station.Sent > 0 {
@ -154,7 +155,7 @@ func (w *WiFiModule) Show(by string) error {
}
if nrows > 0 {
core.AsTable(os.Stdout, columns, rows)
tui.Table(os.Stdout, columns, rows)
}
w.Session.Refresh()

View file

@ -5,12 +5,14 @@ import (
"net"
"regexp"
"github.com/bettercap/bettercap/core"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/packets"
"github.com/bettercap/bettercap/session"
"github.com/google/gopacket/layers"
"github.com/evilsocket/islazy/str"
"github.com/evilsocket/islazy/tui"
)
var (
@ -52,7 +54,7 @@ func NewWOL(s *session.Session) *WOL {
func parseMAC(args []string) (string, error) {
mac := "ff:ff:ff:ff:ff:ff"
if len(args) == 1 {
tmp := core.Trim(args[0])
tmp := str.Trim(args[0])
if tmp != "" {
if !reMAC.MatchString(tmp) {
return "", fmt.Errorf("%s is not a valid MAC address.", tmp)
@ -103,7 +105,7 @@ func (w *WOL) wolETH(mac string) error {
defer w.SetRunning(false, nil)
payload := buildPayload(mac)
log.Info("Sending %d bytes of ethernet WOL packet to %s", len(payload), core.Bold(mac))
log.Info("Sending %d bytes of ethernet WOL packet to %s", len(payload), tui.Bold(mac))
eth := layers.Ethernet{
SrcMAC: w.Session.Interface.HW,
DstMAC: layers.EthernetBroadcast,
@ -124,7 +126,7 @@ func (w *WOL) wolUDP(mac string) error {
defer w.SetRunning(false, nil)
payload := buildPayload(mac)
log.Info("Sending %d bytes of UDP WOL packet to %s", len(payload), core.Bold(mac))
log.Info("Sending %d bytes of UDP WOL packet to %s", len(payload), tui.Bold(mac))
eth := layers.Ethernet{
SrcMAC: w.Session.Interface.HW,