Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BUILD=$(shell git rev-parse HEAD)
DIRBASE=./build
DIR=${DIRBASE}/${VERSION}/${BUILD}/bin

LDFLAGS=-ldflags "-s -w ${XBUILD} -buildid=${BUILD} -X github.com/jpillora/chisel/share.BuildVersion=${VERSION}"
LDFLAGS=-ldflags "-s -w ${XBUILD} -buildid=${BUILD} -X tunnel/share.BuildVersion=${VERSION}"

GOFILES=`go list ./...`
GOFILESNOTEST=`go list ./... | grep -v test`
Expand All @@ -15,16 +15,16 @@ all:
@goreleaser build --skip-validate --single-target --config .github/goreleaser.yml

freebsd: lint
env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-freebsd_amd64 .
env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/tunnel-freebsd_amd64 .

linux: lint
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-linux_amd64 .
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/tunnel-linux_amd64 .

windows: lint
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-windows_amd64 .
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/tunnel-windows_amd64 .

darwin:
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-darwin_amd64 .
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/tunnel-darwin_amd64 .

docker:
@docker build .
Expand Down
74 changes: 74 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@echo off
REM ============================================================
REM Build script - Compila o cliente tunnel para Windows com garble
REM Requer Go 1.23+ instalado no PATH
REM
REM Tecnicas de evasao aplicadas:
REM 1. garble -literals : ofusca strings/literais
REM 2. garble -tiny : remove debug info, encurta simbolos
REM 3. garble -seed=random : seed aleatoria (binario unico a cada build)
REM 4. GOGARBLE=* : ofusca TODOS os pacotes (inclui dependencias)
REM 5. goversioninfo : adiciona VERSIONINFO ao PE
REM 6. -ldflags="-s -w" : strip de simbolos e DWARF
REM 7. -buildid= : remove build ID do linker
REM 8. -trimpath : remove paths do filesystem
REM ============================================================

setlocal

echo [*] Verificando Go...
where go >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo [!] Go nao encontrado. Instale de https://go.dev/dl/
exit /b 1
)

for /f "tokens=3" %%v in ('go version') do set GOVER=%%v
echo [*] Go versao: %GOVER%

echo [*] Instalando/atualizando dependencias...
go install mvdan.cc/garble@latest
if %ERRORLEVEL% neq 0 (
echo [!] Falha ao instalar garble
exit /b 1
)
go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest
if %ERRORLEVEL% neq 0 (
echo [!] Falha ao instalar goversioninfo
exit /b 1
)

echo [*] Gerando metadados VERSIONINFO do Windows...
goversioninfo -64 -o resource.syso versioninfo.json

echo [*] Compilando com garble (ofuscacao total + seed aleatoria)...
set GOGARBLE=*
set CGO_ENABLED=0
set GOOS=windows
set GOARCH=amd64

if not exist build mkdir build

garble -literals -tiny -seed=random build -trimpath -ldflags="-s -w -buildid=" -o build\tunnel-windows-amd64.exe .

if %ERRORLEVEL% equ 0 (
echo.
echo [OK] Binario gerado: build\tunnel-windows-amd64.exe
for %%A in (build\tunnel-windows-amd64.exe) do echo [*] Tamanho: %%~zA bytes

REM UPX packing opcional
where upx >nul 2>&1
if %ERRORLEVEL% equ 0 (
echo [*] Aplicando UPX (compressao LZMA)...
copy /y build\tunnel-windows-amd64.exe build\tunnel-windows-amd64-packed.exe >nul
upx --best --lzma --force build\tunnel-windows-amd64-packed.exe
for %%A in (build\tunnel-windows-amd64-packed.exe) do echo [*] Binario packed: build\tunnel-windows-amd64-packed.exe (%%~zA bytes)
) else (
echo [!] UPX nao encontrado (opcional). Instale de https://upx.github.io/
)
) else (
echo [!] Falha na compilacao
exit /b 1
)

endlocal
67 changes: 67 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# ============================================================
# Build script - Compila o cliente tunnel para Windows com garble
# Requer Go 1.23+ instalado no PATH
#
# Tecnicas de evasao aplicadas:
# 1. garble -literals : ofusca strings/literais
# 2. garble -tiny : remove debug info, encurta simbolos
# 3. garble -seed=random : seed aleatoria (binario unico a cada build)
# 4. GOGARBLE=* : ofusca TODOS os pacotes (inclui dependencias)
# 5. goversioninfo : adiciona VERSIONINFO ao PE (binarios sem metadata sao suspeitos)
# 6. -ldflags="-s -w" : strip de simbolos e DWARF
# 7. -buildid= : remove build ID do linker
# 8. -trimpath : remove paths do filesystem
# ============================================================

set -euo pipefail

echo "[*] Verificando Go..."
if ! command -v go &>/dev/null; then
echo "[!] Go nao encontrado. Instale de https://go.dev/dl/"
exit 1
fi

GOVER=$(go version | awk '{print $3}')
echo "[*] Go versao: $GOVER"

echo "[*] Instalando/atualizando dependencias..."
go install mvdan.cc/garble@latest
go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest

echo "[*] Gerando metadados VERSIONINFO do Windows..."
goversioninfo -64 -o resource.syso versioninfo.json

echo "[*] Compilando com garble (ofuscacao total + seed aleatoria)..."
export GOGARBLE=*
export CGO_ENABLED=0
export GOOS=windows
export GOARCH=amd64

mkdir -p build

garble -literals -tiny -seed=random build \
-trimpath \
-ldflags="-s -w -buildid=" \
-o build/tunnel-windows-amd64.exe .

if [ -f build/tunnel-windows-amd64.exe ]; then
SIZE=$(stat -f%z build/tunnel-windows-amd64.exe 2>/dev/null || stat -c%s build/tunnel-windows-amd64.exe 2>/dev/null)
echo ""
echo "[OK] Binario gerado: build/tunnel-windows-amd64.exe"
echo "[*] Tamanho: $SIZE bytes"

# UPX packing (opcional, muda completamente a assinatura do binario)
if command -v upx &>/dev/null; then
echo "[*] Aplicando UPX (compressao LZMA)..."
cp build/tunnel-windows-amd64.exe build/tunnel-windows-amd64-packed.exe
upx --best --lzma --force build/tunnel-windows-amd64-packed.exe
PACKED_SIZE=$(stat -f%z build/tunnel-windows-amd64-packed.exe 2>/dev/null || stat -c%s build/tunnel-windows-amd64-packed.exe 2>/dev/null)
echo "[*] Binario packed: build/tunnel-windows-amd64-packed.exe ($PACKED_SIZE bytes)"
else
echo "[!] UPX nao encontrado (opcional). Instale com: apt install upx-ucl"
fi
else
echo "[!] Falha na compilacao"
exit 1
fi
16 changes: 8 additions & 8 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
"time"

"github.com/gorilla/websocket"
chshare "github.com/jpillora/chisel/share"
"github.com/jpillora/chisel/share/ccrypto"
"github.com/jpillora/chisel/share/cio"
"github.com/jpillora/chisel/share/cnet"
"github.com/jpillora/chisel/share/settings"
"github.com/jpillora/chisel/share/tunnel"
chshare "tunnel/share"
"tunnel/share/ccrypto"
"tunnel/share/cio"
"tunnel/share/cnet"
"tunnel/share/settings"
"tunnel/share/tunnel"

"golang.org/x/crypto/ssh"
"golang.org/x/net/proxy"
Expand Down Expand Up @@ -175,7 +175,7 @@ func NewClient(c *Config) (*Client, error) {
client.sshConfig = &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{ssh.Password(pass)},
ClientVersion: "SSH-" + chshare.ProtocolVersion + "-client",
ClientVersion: "SSH-2.0-Go",
HostKeyCallback: client.verifyServer,
Timeout: settings.EnvDuration("SSH_TIMEOUT", 30*time.Second),
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func (c *Client) Start(ctx context.Context) error {
via = " via " + c.proxyURL.String()
}
c.Infof("Connecting to %s%s\n", c.server, via)
//connect to chisel server
//connect to tunnel server
eg.Go(func() error {
return c.connectionLoop(ctx)
})
Expand Down
12 changes: 6 additions & 6 deletions client/client_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

"github.com/gorilla/websocket"
"github.com/jpillora/backoff"
chshare "github.com/jpillora/chisel/share"
"github.com/jpillora/chisel/share/cnet"
"github.com/jpillora/chisel/share/cos"
"github.com/jpillora/chisel/share/settings"
chshare "tunnel/share"
"tunnel/share/cnet"
"tunnel/share/cos"
"tunnel/share/settings"
"golang.org/x/crypto/ssh"
)

Expand Down Expand Up @@ -64,7 +64,7 @@ func (c *Client) connectionLoop(ctx context.Context) error {
return nil
}

// connectionOnce connects to the chisel server and blocks
// connectionOnce connects to the tunnel server and blocks
func (c *Client) connectionOnce(ctx context.Context) (connected bool, err error) {
//already closed?
select {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (c *Client) connectionOnce(ctx context.Context) (connected bool, err error)
return false, err
}
defer sshConn.Close()
// chisel client handshake (reverse of server handshake)
// client handshake (reverse of server handshake)
// send configuration
c.Debugf("Sending config")
t0 := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/jpillora/chisel/share/ccrypto"
"tunnel/share/ccrypto"
"golang.org/x/crypto/ssh"
)

Expand Down
11 changes: 2 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jpillora/chisel
module tunnel

go 1.25

Expand All @@ -9,17 +9,10 @@ require (
github.com/fsnotify/fsnotify v1.9.0
github.com/gorilla/websocket v1.5.3
github.com/jpillora/backoff v1.0.0
github.com/jpillora/requestlog v1.0.0
github.com/jpillora/sizestr v1.0.0
golang.org/x/crypto v0.48.0
golang.org/x/net v0.50.0
golang.org/x/sync v0.19.0
)

require (
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 // indirect
github.com/jpillora/ansi v1.0.3 // indirect
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
)
require golang.org/x/sys v0.41.0 // indirect
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 h1:axBiC50cNZOs7ygH5BgQp4N+aYrZ2DNpWZ1KG3VOSOM=
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2/go.mod h1:jnzFpU88PccN/tPPhCpnNU8mZphvKxYM9lLNkd8e+os=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jpillora/ansi v1.0.3 h1:nn4Jzti0EmRfDxm7JtEs5LzCbNwd5sv+0aE+LdS9/ZQ=
github.com/jpillora/ansi v1.0.3/go.mod h1:D2tT+6uzJvN1nBVQILYWkIdq7zG+b5gcFN5WI/VyjMY=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jpillora/requestlog v1.0.0 h1:bg++eJ74T7DYL3DlIpiwknrtfdUA9oP/M4fL+PpqnyA=
github.com/jpillora/requestlog v1.0.0/go.mod h1:HTWQb7QfDc2jtHnWe2XEIEeJB7gJPnVdpNn52HXPvy8=
github.com/jpillora/sizestr v1.0.0 h1:4tr0FLxs1Mtq3TnsLDV+GYUWG7Q26a6s+tV5Zfw2ygw=
github.com/jpillora/sizestr v1.0.0/go.mod h1:bUhLv4ctkknatr6gR42qPxirmd5+ds1u7mzD+MZ33f0=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce h1:fb190+cK2Xz/dvi9Hv8eCYJYvIGUTN2/KLq1pT6CjEc=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
Expand All @@ -26,5 +18,3 @@ golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
Loading