Bug 280591 - net/spoofdpi: New port: Simple and fast anti-censorship tool
Summary: net/spoofdpi: New port: Simple and fast anti-censorship tool
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Vladimir Druzenko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-03 14:57 UTC by Yusuf Yaman
Modified: 2024-08-06 00:54 UTC (History)
2 users (show)

See Also:


Attachments
net/spoofdpi (6.77 KB, patch)
2024-08-03 14:58 UTC, Yusuf Yaman
no flags Details | Diff
poudriere testport log (29.67 KB, text/plain)
2024-08-03 14:59 UTC, Yusuf Yaman
no flags Details
portlint log (12 bytes, text/plain)
2024-08-03 14:59 UTC, Yusuf Yaman
no flags Details
[second patch] net/spoofdpi: Create rc.d script, user and group and replace binary name with spoofdpi (3.25 KB, patch)
2024-08-04 12:20 UTC, Yusuf Yaman
no flags Details | Diff
net/spoofdpi (8.98 KB, patch)
2024-08-05 22:26 UTC, Yusuf Yaman
no flags Details | Diff
poudriere testport log (23.97 KB, text/plain)
2024-08-05 22:26 UTC, Yusuf Yaman
no flags Details
portlint log (12 bytes, text/plain)
2024-08-05 22:26 UTC, Yusuf Yaman
no flags Details
net/spoofdpi (8.98 KB, patch)
2024-08-05 22:51 UTC, Yusuf Yaman
no flags Details | Diff
poudriere testport log (23.97 KB, text/plain)
2024-08-05 22:51 UTC, Yusuf Yaman
no flags Details
portlint log (12 bytes, text/plain)
2024-08-05 22:51 UTC, Yusuf Yaman
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuf Yaman 2024-08-03 14:57:32 UTC
SpoofDPI is a simple and fast anti-censorship tool written in Go that bypasses
Deep Packet Inspection (DPI) by splitting HTTPS requests
into chunks and sending the first byte separately.
Comment 1 Yusuf Yaman 2024-08-03 14:58:43 UTC
Created attachment 252479 [details]
net/spoofdpi
Comment 2 Yusuf Yaman 2024-08-03 14:59:19 UTC
Created attachment 252480 [details]
poudriere testport log
Comment 3 Yusuf Yaman 2024-08-03 14:59:35 UTC
Created attachment 252481 [details]
portlint log
Comment 4 Vladimir Druzenko freebsd_committer freebsd_triage 2024-08-04 01:04:03 UTC
Maybe create rc.d start script?
I can help with this.
Comment 5 Yusuf Yaman 2024-08-04 10:14:56 UTC
I never created a rc.d script before, so I would like to get help. I tried writing a rc.d script now and it starts the program but i don't want to see program's output transferred into terminal. Also I't doesn't run in background mode. Here is my uncompleted script. I looked to moused's rc.d script for help.

#!/bin/sh

. /etc/rc.subr

name="spoofdpi"
desc="SpoofDPI daemon"
rcvar="${name}_enable"
command="/usr/local/bin/spoof-dpi"
start_cmd="${name}_start"
stop_cmd=":"
load_rc_config $name

spoofdpi_start()
{
        local myflags

        myflags="$spoofdpi_flags"

        startmsg -n "Starting ${name}"
        ${command} ${myflags}
        startmsg '.'
}

run_rc_command "$1" &

The program can take some arguments like:

  -addr string
        listen address (default "127.0.0.1")
  -debug
        enable debug output
  -dns-addr string
        dns address (default "8.8.8.8")
  -dns-port int
        port number for dns (default 53)
  -enable-doh
        enable 'dns over https'
  -no-banner
        disable banner
  -pattern string
        bypass DPI only on packets matching this regex pattern
  -port int
        port (default 8080)
  -timeout int
        timeout in milliseconds. no timeout when not given
  -url value
        Bypass DPI only on this url, can be passed multiple times
  -v    print spoof-dpi's version. this may contain some other relevant information
  -window-size int
        chunk size, in number of bytes, for fragmented client hello,
        try lower values if the default value doesn't bypass the DPI;
        when not given, the client hello packet will be sent in two parts:
        fragmentation for the first data packet and the rest
Comment 6 Vladimir Druzenko freebsd_committer freebsd_triage 2024-08-04 11:18:09 UTC
Lets rename binary file to spoofdpi:
GO_BUILDFLAGS=  -ldflags="-s -w" -o ./build/spoofdpi
PLIST_FILES=    bin/spoofdpi

Try this net/spoofdpi/files/spoofdpi.in (we can add other options like addr, port, dns and etc - what you want):
#!/bin/sh

# PROVIDE: spoofdpi
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf or /etc/rc.conf.local to
# enable spoofdpi:
# spoofdpi_args (str):      Custom additional arguments to be passed
#                           spoofdpi (default empty).
# spoofdpi_user (str):      User to run spoofdpi as. Default
#                           to "%%USER%%" created by the port.
# spoofdpi_log (path):      Console log file (default /dev/null).

. /etc/rc.subr

case $0 in
/etc/rc*)
        # during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
        # so get the name of the script from $_file
        name=$_file
        ;;
*)
        name=$0
        ;;
esac

name=${name##*/}
rcvar="${name}_enable"

load_rc_config "${name}"

eval "${rcvar}=\${${rcvar}:-'NO'}"
eval "_args=\${${name}_args:-''}"
eval "_user=\${${name}_user:-'%%USER%%'}"
eval "_log=\${${name}_log:-/dev/null}"

pidfile="/var/run/${name}.pid"

command="/usr/sbin/daemon"
command_args="-P ${pidfile} -u ${_user} -f -H -o ${_log} -m 3 %%PREFIX%%/bin/spoofdpi -no-banner ${_args}"

run_rc_command "$1"

Also add to Makefile:
USE_RC_SUBR=    ${PORTNAME}
SUB_LIST=       USER=${USERS}
USERS=          spoofdpi
GROUPS=         spoofdpi

UIDs:
spoofdpi:*:380:380:SpoofDPI Daemon:0:0: :/nonexistent:/usr/sbin/nologin
GIDs:
spoofdpi:*:380:
Comment 7 Vladimir Druzenko freebsd_committer freebsd_triage 2024-08-04 11:19:40 UTC
Not tested yet.
Comment 8 Yusuf Yaman 2024-08-04 12:19:35 UTC
I tested rc.d script and it seems to work. I just fixed the UID, i guess there was a syntax error and it was causing error when system trying to create the group.

Very thanks. I appreciate it.

I hope you don't mind me attaching a second patch instead of full patch again.
Comment 9 Yusuf Yaman 2024-08-04 12:20:33 UTC
Created attachment 252497 [details]
[second patch] net/spoofdpi: Create rc.d script, user and group and replace binary name with spoofdpi
Comment 10 Yusuf Yaman 2024-08-04 12:22:03 UTC
> I just fixed the UID, i guess there was a syntax error
> and it was causing error when system trying to create the group.

Sorry, it wasn't group error, it was user error.
Comment 11 Yusuf Yaman 2024-08-04 12:24:21 UTC
I guess rc.d script doesn't work without specifying args in /etc/rc.conf. I'll test it more...
Comment 12 Vladimir Druzenko freebsd_committer freebsd_triage 2024-08-05 01:11:37 UTC
Do you use IRC or Discord?
Comment 13 Yusuf Yaman 2024-08-05 12:20:21 UTC
I don't use Discord but I just created an IRC account.

My nickname is nxjoseph
Comment 14 Vladimir Druzenko freebsd_committer freebsd_triage 2024-08-05 12:47:18 UTC
PORTNAME=	spoofdpi
DISTVERSIONPREFIX=	v
DISTVERSION=	0.10.4
CATEGORIES=	net

MAINTAINER=	nxjoseph@protonmail.com
COMMENT=	Simple and fast anti-censorship tool
WWW=		https://github.com/xvzc/SpoofDPI

LICENSE=	APACHE20

USES=		go:modules
USE_GITHUB=	yes
GH_ACCOUNT=	xvzc
GH_PROJECT=	SpoofDPI
GH_TUPLE=	atomicgo:cursor:v0.2.0:atomicgo_cursor/vendor/atomicgo.dev/cursor \
		atomicgo:keyboard:v0.2.9:atomicgo_keyboard/vendor/atomicgo.dev/keyboard \
		atomicgo:schedule:v0.1.0:atomicgo_schedule/vendor/atomicgo.dev/schedule \
		containerd:console:v1.0.3:containerd_console/vendor/github.com/containerd/console \
		golang:mod:v0.18.0:golang_mod/vendor/golang.org/x/mod \
		golang:net:v0.27.0:golang_net/vendor/golang.org/x/net \
		golang:sync:v0.7.0:golang_sync/vendor/golang.org/x/sync \
		golang:sys:v0.22.0:golang_sys/vendor/golang.org/x/sys \
		golang:term:v0.22.0:golang_term/vendor/golang.org/x/term \
		golang:text:v0.16.0:golang_text/vendor/golang.org/x/text \
		golang:tools:v0.22.0:golang_tools/vendor/golang.org/x/tools \
		gookit:color:v1.5.4:gookit_color/vendor/github.com/gookit/color \
		likexian:doh:v0.7.1:likexian_doh/vendor/github.com/likexian/doh \
		likexian:gokit:v0.25.15:likexian_gokit/vendor/github.com/likexian/gokit \
		lithammer:fuzzysearch:v1.1.8:lithammer_fuzzysearch/vendor/github.com/lithammer/fuzzysearch \
		mattn:go-runewidth:v0.0.15:mattn_go_runewidth/vendor/github.com/mattn/go-runewidth \
		miekg:dns:v1.1.61:miekg_dns/vendor/github.com/miekg/dns \
		pterm:pterm:v0.12.79:pterm_pterm/vendor/github.com/pterm/pterm \
		rivo:uniseg:v0.4.4:rivo_uniseg/vendor/github.com/rivo/uniseg \
		sirupsen:logrus:v1.9.3:sirupsen_logrus/vendor/github.com/sirupsen/logrus \
		xo:terminfo:abceb7e1c41e:xo_terminfo/vendor/github.com/xo/terminfo

USE_RC_SUBR=	${PORTNAME}
GO_TARGET=	./cmd/spoof-dpi:${PORTNAME}
GO_BUILDFLAGS=	-ldflags="-s -w"
SUB_LIST=	USER=${USERS}
USERS=		${PORTNAME}
GROUPS=		${PORTNAME}

PLIST_FILES=	bin/${PORTNAME}

.include <bsd.port.mk>
Comment 15 Vladimir Druzenko freebsd_committer freebsd_triage 2024-08-05 12:48:47 UTC
#!/bin/sh

# PROVIDE: spoofdpi
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf or /etc/rc.conf.local to
# enable spoofdpi:
# spoofdpi_args (str):	Custom additional arguments to be passed
#			spoofdpi (default empty).
# spoofdpi_user (str):	User to run spoofdpi as. Default
#			to "%%USER%%" created by the port.
# spoofdpi_log (path):	Console log file (default /dev/null).

. /etc/rc.subr

case $0 in
/etc/rc*)
	# during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
	# so get the name of the script from $_file
	name=$_file
	;;
*)
	name=$0
	;;
esac

name=${name##*/}
rcvar="${name}_enable"

load_rc_config "${name}"

eval "${rcvar}=\${${rcvar}:-'NO'}"
eval "_args=\${${name}_args:-''}"
eval "_user=\${${name}_user:-'%%USER%%'}"
eval "_log=\${${name}_log:-/dev/null}"

pidfile="/var/run/${name}.pid"

command="/usr/sbin/daemon"
command_args="-P ${pidfile} -u ${_user} -f -H -o ${_log} -m 3 %%PREFIX%%/bin/spoofdpi -no-banner ${_args}"

run_rc_command "$1"
Comment 16 Yusuf Yaman 2024-08-05 22:26:00 UTC
Created attachment 252529 [details]
net/spoofdpi

Attaching new complete patch and marking second patch obsolete.
Comment 17 Yusuf Yaman 2024-08-05 22:26:14 UTC
Created attachment 252530 [details]
poudriere testport log
Comment 18 Yusuf Yaman 2024-08-05 22:26:28 UTC
Created attachment 252531 [details]
portlint log
Comment 19 Yusuf Yaman 2024-08-05 22:51:07 UTC
Created attachment 252533 [details]
net/spoofdpi

use substitutions like %%USER%% and %%PREFIX%% in service file.
Comment 20 Yusuf Yaman 2024-08-05 22:51:32 UTC
Created attachment 252534 [details]
poudriere testport log
Comment 21 Yusuf Yaman 2024-08-05 22:51:44 UTC
Created attachment 252535 [details]
portlint log
Comment 22 commit-hook freebsd_committer freebsd_triage 2024-08-05 23:05:47 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=3ad03358f6959b68ea10c2d395274dda595afec9

commit 3ad03358f6959b68ea10c2d395274dda595afec9
Author:     Yusuf Yaman <nxjoseph@protonmail.com>
AuthorDate: 2024-08-05 23:01:57 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2024-08-05 23:01:57 +0000

    net/spoofdpi: New port: Simple and fast anti-censorship tool

    SpoofDPI is a simple and fast anti-censorship tool written in Go that
    bypasses Deep Packet Inspection (DPI) by splitting HTTPS requests
    into chunks and sending the first byte separately.

    It can be run as daemon via rc.d script spoofdpi.

    https://github.com/xvzc/SpoofDPI

    PR:     280591

 GIDs                                 |  2 +-
 UIDs                                 |  2 +-
 net/Makefile                         |  1 +
 net/spoofdpi/Makefile (new)          | 47 ++++++++++++++++++++++++++++++++++++
 net/spoofdpi/distinfo (new)          | 45 ++++++++++++++++++++++++++++++++++
 net/spoofdpi/files/spoofdpi.in (new) | 43 +++++++++++++++++++++++++++++++++
 net/spoofdpi/pkg-descr (new)         |  3 +++
 7 files changed, 141 insertions(+), 2 deletions(-)
Comment 23 Vladimir Druzenko freebsd_committer freebsd_triage 2024-08-05 23:09:31 UTC
Thanks!
Comment 24 commit-hook freebsd_committer freebsd_triage 2024-08-06 00:54:59 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=46b3743b84691248050b1e8e810355d17f5bb084

commit 46b3743b84691248050b1e8e810355d17f5bb084
Author:     Vladimir Druzenko <vvd@FreeBSD.org>
AuthorDate: 2024-08-06 00:52:18 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2024-08-06 00:52:18 +0000

    UIDs: fix typo in username for net/spoofdpi

    PR:     280591
    Fixes:  3ad03358f695 (New port: Simple and fast anti-censorship tool)

 UIDs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)