Compare commits

...

18 commits

Author SHA1 Message Date
evilsocket
1001cea8f2 misc: small fix or general refactoring i did not bother commenting
Some checks are pending
Build and Push Docker Images / docker (push) Waiting to run
Linux tests / build (1.24.x, ubuntu-latest) (push) Waiting to run
macOS tests / build (1.24.x, macos-latest) (push) Waiting to run
Windows tests / build (1.24.x, windows-latest) (push) Waiting to run
2025-08-23 17:12:07 +02:00
evilsocket
204997c8b5 misc: small fix or general refactoring i did not bother commenting
Some checks are pending
Build and Push Docker Images / docker (push) Waiting to run
Linux tests / build (1.24.x, ubuntu-latest) (push) Waiting to run
macOS tests / build (1.24.x, macos-latest) (push) Waiting to run
Windows tests / build (1.24.x, windows-latest) (push) Waiting to run
2025-08-23 14:22:11 +02:00
evilsocket
4ec2753fad releasing version 2.41.4
Some checks failed
Build and Push Docker Images / docker (push) Has been cancelled
Linux tests / build (1.24.x, ubuntu-latest) (push) Has been cancelled
macOS tests / build (1.24.x, macos-latest) (push) Has been cancelled
Windows tests / build (1.24.x, windows-latest) (push) Has been cancelled
2025-08-18 19:15:44 +02:00
evilsocket
42da612113 hotfix: hotfix 2 for tcp.proxy 2025-08-18 19:14:05 +02:00
evilsocket
fc65cde728 releasing version 2.41.3 2025-08-18 17:08:42 +02:00
evilsocket
cc475ddfba hotfix: fixed tcp_proxy onData bug 2025-08-18 17:08:14 +02:00
evilsocket
cfc6d55462 misc: removed bogus test 2025-08-18 15:25:26 +02:00
evilsocket
ccf4fa09e2 releasing version 2.41.2 2025-08-18 15:10:45 +02:00
evilsocket
1e235181aa fix: fixed tcp.proxy onData return value bug (fixes #788) 2025-08-18 15:01:34 +02:00
Simone Margaritelli
453c417e92
Merge pull request #1218 from kkrypt0nn/master
Some checks failed
Build and Push Docker Images / docker (push) Has been cancelled
Linux tests / build (1.24.x, ubuntu-latest) (push) Has been cancelled
macOS tests / build (1.24.x, macos-latest) (push) Has been cancelled
Windows tests / build (1.24.x, windows-latest) (push) Has been cancelled
feat: Add default username and password for API
2025-08-09 13:48:07 +02:00
Krypton
d1925cd926
fix: Consistency between HTTP(S) servers 2025-08-08 18:46:06 +02:00
Krypton
d60d4612f2
feat: Add default username and password for API 2025-08-08 18:34:31 +02:00
Simone Margaritelli
8bd6052851
Merge pull request #1217 from bettercap/dependabot/github_actions/actions/download-artifact-5
Some checks are pending
Build and Push Docker Images / docker (push) Waiting to run
Linux tests / build (1.24.x, ubuntu-latest) (push) Waiting to run
macOS tests / build (1.24.x, macos-latest) (push) Waiting to run
Windows tests / build (1.24.x, windows-latest) (push) Waiting to run
build(deps): bump actions/download-artifact from 4 to 5
2025-08-08 16:06:45 +02:00
Simone Margaritelli
a23ba5fcba
Merge pull request #1210 from kkrypt0nn/master
fix: `OnPacket` proxy plugin callback signature check
2025-08-08 16:06:26 +02:00
dependabot[bot]
be76c0a7da
build(deps): bump actions/download-artifact from 4 to 5
Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 4 to 5.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-06 04:52:30 +00:00
Krypton
faee64a2c0 fix: Consistency and small typo 2025-07-16 21:01:15 +02:00
Krypton
0f68fcca8b fix: Small typo in ticker off description 2025-07-15 22:10:28 +02:00
Krypton
5a6a5fbbdf fix: Callback signature check 2025-07-15 21:19:00 +02:00
12 changed files with 218 additions and 55 deletions

View file

@ -99,7 +99,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v5
with:
pattern: release-artifacts-*
merge-multiple: true

View file

@ -16,6 +16,8 @@
<a href="https://github.com/bettercap/bettercap/actions/workflows/test-on-macos.yml"><img alt="Tests on macOS" src="https://github.com/bettercap/bettercap/actions/workflows/test-on-macos.yml/badge.svg"></a>
<a href="https://github.com/bettercap/bettercap/actions/workflows/test-on-windows.yml"><img alt="Tests on Windows" src="https://github.com/bettercap/bettercap/actions/workflows/test-on-windows.yml/badge.svg"></a>
<a href="https://hub.docker.com/r/bettercap/bettercap"><img alt="Docker Hub" src="https://img.shields.io/docker/v/bettercap/bettercap?logo=docker"></a>
<img src="https://img.shields.io/badge/human-coded-brightgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0ibHVjaWRlIGx1Y2lkZS1wZXJzb24tc3RhbmRpbmctaWNvbiBsdWNpZGUtcGVyc29uLXN0YW5kaW5nIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjUiIHI9IjEiLz48cGF0aCBkPSJtOSAyMCAzLTYgMyA2Ii8+PHBhdGggZD0ibTYgOCA2IDIgNi0yIi8+PHBhdGggZD0iTTEyIDEwdjQiLz48L3N2Zz4=" alt="This project is 100% made by humans."/>
</p>
</p>

View file

@ -2,7 +2,7 @@ package core
const (
Name = "bettercap"
Version = "2.41.1"
Version = "2.41.4"
Author = "Simone 'evilsocket' Margaritelli"
Website = "https://bettercap.org/"
)

View file

@ -90,12 +90,12 @@ func NewRestAPI(s *session.Session) *RestAPI {
"Value of the Access-Control-Allow-Origin header of the API server."))
mod.AddParam(session.NewStringParameter("api.rest.username",
"",
"user",
"",
"API authentication username."))
mod.AddParam(session.NewStringParameter("api.rest.password",
"",
"pass",
"",
"API authentication password."))

View file

@ -31,20 +31,20 @@ func NewHttpServer(s *session.Session) *HttpServer {
mod.AddParam(session.NewStringParameter("http.server.address",
session.ParamIfaceAddress,
session.IPv4Validator,
"Address to bind the http server to."))
"Address to bind the HTTP server to."))
mod.AddParam(session.NewIntParameter("http.server.port",
"80",
"Port to bind the http server to."))
"Port to bind the HTTP server to."))
mod.AddHandler(session.NewModuleHandler("http.server on", "",
"Start httpd server.",
"Start HTTP server.",
func(args []string) error {
return mod.Start()
}))
mod.AddHandler(session.NewModuleHandler("http.server off", "",
"Stop httpd server.",
"Stop HTTP server.",
func(args []string) error {
return mod.Stop()
}))

View file

@ -35,11 +35,11 @@ func NewHttpsServer(s *session.Session) *HttpsServer {
mod.AddParam(session.NewStringParameter("https.server.address",
session.ParamIfaceAddress,
session.IPv4Validator,
"Address to bind the http server to."))
"Address to bind the HTTPS server to."))
mod.AddParam(session.NewIntParameter("https.server.port",
"443",
"Port to bind the http server to."))
"Port to bind the HTTPS server to."))
mod.AddParam(session.NewStringParameter("https.server.certificate",
"~/.bettercap-httpd.cert.pem",
@ -54,13 +54,13 @@ func NewHttpsServer(s *session.Session) *HttpsServer {
tls.CertConfigToModule("https.server", &mod.SessionModule, tls.DefaultLegitConfig)
mod.AddHandler(session.NewModuleHandler("https.server on", "",
"Start https server.",
"Start HTTPS server.",
func(args []string) error {
return mod.Start()
}))
mod.AddHandler(session.NewModuleHandler("https.server off", "",
"Stop https server.",
"Stop HTTPS server.",
func(args []string) error {
return mod.Stop()
}))

View file

@ -16,15 +16,13 @@ import (
"github.com/evilsocket/islazy/fs"
)
type hookFunc func(q *nfqueue.Nfqueue, a nfqueue.Attribute) int
type PacketProxy struct {
session.SessionModule
chainName string
rule string
queue *nfqueue.Nfqueue
queueNum int
queueCb hookFunc
queueCb func(q *nfqueue.Nfqueue, a nfqueue.Attribute) int
pluginPath string
plugin *plugin.Plugin
}
@ -151,7 +149,7 @@ func (mod *PacketProxy) Configure() (err error) {
return
} else if sym, err = mod.plugin.Lookup("OnPacket"); err != nil {
return
} else if mod.queueCb, ok = sym.(hookFunc); !ok {
} else if mod.queueCb, ok = sym.(func(q *nfqueue.Nfqueue, a nfqueue.Attribute) int); !ok {
return fmt.Errorf("Symbol OnPacket is not a valid callback function.")
}

View file

@ -1,6 +1,7 @@
package tcp_proxy
import (
"encoding/json"
"net"
"strings"
@ -55,12 +56,36 @@ func (s *TcpProxyScript) OnData(from, to net.Addr, data []byte, callback func(ca
log.Error("error while executing onData callback: %s", err)
return nil
} else if ret != nil {
array, ok := ret.([]byte)
if !ok {
log.Error("error while casting exported value to array of byte: value = %+v", ret)
}
return array
return toByteArray(ret)
}
}
return nil
}
func toByteArray(ret interface{}) []byte {
// this approach is a bit hacky but it handles all cases
// serialize ret to JSON
if jsonData, err := json.Marshal(ret); err == nil {
// attempt to deserialize as []float64
var back2Array []float64
if err := json.Unmarshal(jsonData, &back2Array); err == nil {
result := make([]byte, len(back2Array))
for i, num := range back2Array {
if num >= 0 && num <= 255 {
result[i] = byte(num)
} else {
log.Error("array element at index %d is not a valid byte value %d", i, num)
return nil
}
}
return result
} else {
log.Error("failed to deserialize %+v to []float64: %v", ret, err)
}
} else {
log.Error("failed to serialize %+v to JSON: %v", ret, err)
}
return nil
}

View file

@ -0,0 +1,169 @@
package tcp_proxy
import (
"net"
"testing"
"github.com/evilsocket/islazy/plugin"
)
func TestOnData_NoReturn(t *testing.T) {
jsCode := `
function onData(from, to, data, callback) {
// don't return anything
}
`
plug, err := plugin.Parse(jsCode)
if err != nil {
t.Fatalf("Failed to parse plugin: %v", err)
}
script := &TcpProxyScript{
Plugin: plug,
doOnData: plug.HasFunc("onData"),
}
from := &net.TCPAddr{IP: net.ParseIP("192.168.1.1"), Port: 1234}
to := &net.TCPAddr{IP: net.ParseIP("192.168.1.2"), Port: 5678}
data := []byte("test data")
result := script.OnData(from, to, data, nil)
if result != nil {
t.Errorf("Expected nil result when callback returns nothing, got %v", result)
}
}
func TestOnData_ReturnsArrayOfIntegers(t *testing.T) {
jsCode := `
function onData(from, to, data, callback) {
// Return modified data as array of integers
return [72, 101, 108, 108, 111]; // "Hello" in ASCII
}
`
plug, err := plugin.Parse(jsCode)
if err != nil {
t.Fatalf("Failed to parse plugin: %v", err)
}
script := &TcpProxyScript{
Plugin: plug,
doOnData: plug.HasFunc("onData"),
}
from := &net.TCPAddr{IP: net.ParseIP("192.168.1.1"), Port: 1234}
to := &net.TCPAddr{IP: net.ParseIP("192.168.1.2"), Port: 5678}
data := []byte("test data")
result := script.OnData(from, to, data, nil)
expected := []byte("Hello")
if result == nil {
t.Fatal("Expected non-nil result when callback returns array of integers")
}
if len(result) != len(expected) {
t.Fatalf("Expected result length %d, got %d", len(expected), len(result))
}
for i, b := range result {
if b != expected[i] {
t.Errorf("Expected byte at index %d to be %d, got %d", i, expected[i], b)
}
}
}
func TestOnData_ReturnsDynamicArray(t *testing.T) {
jsCode := `
function onData(from, to, data, callback) {
var result = [];
for (var i = 0; i < data.length; i++) {
result.push((data[i] + 1) % 256);
}
return result;
}
`
plug, err := plugin.Parse(jsCode)
if err != nil {
t.Fatalf("Failed to parse plugin: %v", err)
}
script := &TcpProxyScript{
Plugin: plug,
doOnData: plug.HasFunc("onData"),
}
from := &net.TCPAddr{IP: net.ParseIP("192.168.1.1"), Port: 1234}
to := &net.TCPAddr{IP: net.ParseIP("192.168.1.2"), Port: 5678}
data := []byte{10, 20, 30, 40, 255}
result := script.OnData(from, to, data, nil)
expected := []byte{11, 21, 31, 41, 0} // 255 + 1 = 256 % 256 = 0
if result == nil {
t.Fatal("Expected non-nil result when callback returns array of integers")
}
if len(result) != len(expected) {
t.Fatalf("Expected result length %d, got %d", len(expected), len(result))
}
for i, b := range result {
if b != expected[i] {
t.Errorf("Expected byte at index %d to be %d, got %d", i, expected[i], b)
}
}
}
func TestOnData_ReturnsMixedArray(t *testing.T) {
jsCode := `
function charToInt(value) {
return value.charCodeAt()
}
function onData(from, to, data) {
st_data = String.fromCharCode.apply(null, data)
if( st_data.indexOf("mysearch") != -1 ) {
payload = "mypayload";
st_data = st_data.replace("mysearch", payload);
res_int_arr = st_data.split("").map(charToInt) // []uint16
res_int_arr[0] = payload.length + 1; // first index is float64 and rest []uint16
return res_int_arr;
}
return data;
}
`
plug, err := plugin.Parse(jsCode)
if err != nil {
t.Fatalf("Failed to parse plugin: %v", err)
}
script := &TcpProxyScript{
Plugin: plug,
doOnData: plug.HasFunc("onData"),
}
from := &net.TCPAddr{IP: net.ParseIP("192.168.1.1"), Port: 1234}
to := &net.TCPAddr{IP: net.ParseIP("192.168.1.6"), Port: 5678}
data := []byte("Hello mysearch world")
result := script.OnData(from, to, data, nil)
expected := []byte("\x0aello mypayload world")
if result == nil {
t.Fatal("Expected non-nil result when callback returns array of integers")
}
if len(result) != len(expected) {
t.Fatalf("Expected result length %d, got %d", len(expected), len(result))
}
for i, b := range result {
if b != expected[i] {
t.Errorf("Expected byte at index %d to be %d, got %d", i, expected[i], b)
}
}
}

View file

@ -43,7 +43,7 @@ func NewTicker(s *session.Session) *Ticker {
}))
mod.AddHandler(session.NewModuleHandler("ticker off", "",
"Stop the maint icker.",
"Stop the main ticker.",
func(args []string) error {
return mod.Stop()
}))

View file

@ -265,8 +265,8 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
mod.AddHandler(probe)
channelSwitchAnnounce := session.NewModuleHandler("wifi.channel_switch_announce bssid channel ", `wifi\.channel_switch_announce ((?:[a-fA-F0-9:]{11,}))\s+((?:[0-9]+))`,
"Start a 802.11 channel hop attack, all client will be force to change the channel lead to connection down.",
channelSwitchAnnounce := session.NewModuleHandler("wifi.channel_switch_announce BSSID CHANNEL ", `wifi\.channel_switch_announce ((?:[a-fA-F0-9:]{11,}))\s+((?:[0-9]+))`,
"Start a 802.11 channel hop attack, all client will be forced to change the channel lead to connection down.",
func(args []string) error {
bssid, err := net.ParseMAC(args[0])
if err != nil {

View file

@ -518,37 +518,6 @@ func TestWiFiModuleProbe(t *testing.T) {
}
}
func TestWiFiModuleChannelSwitchAnnounce(t *testing.T) {
sess := createMockSession()
mod := NewWiFiModule(sess)
// Test CSA handler
handlers := mod.Handlers()
var csaHandler session.ModuleHandler
for _, h := range handlers {
if h.Name == "wifi.channel_switch_announce bssid channel " {
csaHandler = h
break
}
}
if csaHandler.Name == "" {
t.Fatal("CSA handler not found")
}
// Test with valid parameters
err := csaHandler.Exec([]string{"aa:bb:cc:dd:ee:ff", "11"})
if err == nil {
t.Error("Expected error when running CSA without running module")
}
// Test with invalid channel
err = csaHandler.Exec([]string{"aa:bb:cc:dd:ee:ff", "999"})
if err == nil {
t.Error("Expected error with invalid channel")
}
}
func TestWiFiModuleFakeAuth(t *testing.T) {
sess := createMockSession()
mod := NewWiFiModule(sess)