mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
Compare commits
60 Commits
v0.9.4.3
...
6d7f8efc49
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d7f8efc49 | ||
|
|
e46cde8e6e | ||
|
|
52072359f0 | ||
|
|
cafacf35bc | ||
|
|
55dc47bae4 | ||
|
|
14a2548bf5 | ||
|
|
f59ddbb645 | ||
|
|
96f58adc7a | ||
|
|
b20ee9adbe | ||
|
|
7bfb4066cd | ||
|
|
a8a742f48c | ||
|
|
03f1fc4788 | ||
|
|
3ae875f8aa | ||
|
|
300084a654 | ||
|
|
ccef4377df | ||
|
|
3ebb24930e | ||
|
|
aff6fe3966 | ||
|
|
f43030c0b8 | ||
|
|
69e8bb3c7f | ||
|
|
038f64ddad | ||
|
|
abdf88574c | ||
|
|
318c625247 | ||
|
|
3e52d53df0 | ||
|
|
410ba5ae6e | ||
|
|
bee761f0f7 | ||
|
|
863267e659 | ||
|
|
c0299a27e3 | ||
|
|
b9e22fd97e | ||
|
|
b3a6445d13 | ||
|
|
75e3c83d07 | ||
|
|
1aaf73858c | ||
|
|
827b1cf065 | ||
|
|
e0f67fb203 | ||
|
|
da6f4c8536 | ||
|
|
f83ecb64bb | ||
|
|
c634fd156c | ||
|
|
c10cc5b83e | ||
|
|
60988755b7 | ||
|
|
7584d5e38f | ||
|
|
d019627fba | ||
|
|
1ac067ec32 | ||
|
|
1b5811aa9a | ||
|
|
60c3f56c36 | ||
|
|
a0cfbbf958 | ||
|
|
437c988f48 | ||
|
|
a9a64b0462 | ||
|
|
9887e470dc | ||
|
|
5bacfcb65f | ||
|
|
0f04698f07 | ||
|
|
31d5e5598b | ||
|
|
66e2cc2bc4 | ||
|
|
8fcc64ad0c | ||
|
|
d2f3271542 | ||
|
|
942c4956b8 | ||
|
|
77a24a7ec1 | ||
|
|
43999d6077 | ||
|
|
697f9fc986 | ||
|
|
8e76197dff | ||
|
|
190f46b6d7 | ||
|
|
41e26b3ace |
61
.github/workflows/build.yml
vendored
61
.github/workflows/build.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
- arch: arm64
|
||||
tool: aarch64-unknown-linux-musl
|
||||
- arch: arm
|
||||
tool: arm-unknown-linux-musleabi
|
||||
tool: armv6-unknown-linux-musleabi
|
||||
- arch: mips64
|
||||
tool: mips64-unknown-linux-musl
|
||||
- arch: mipselsf
|
||||
@@ -88,6 +88,8 @@ jobs:
|
||||
LUAJIT_LUAVER: 5.1
|
||||
MINSIZE: -flto=auto -ffunction-sections -fdata-sections
|
||||
LDMINSIZE: -Wl,--gc-sections -flto=auto
|
||||
#current toolchain's musl is not PIC. will be broken by upx
|
||||
#PIC: -fpic
|
||||
run: |
|
||||
DEPS_DIR=$GITHUB_WORKSPACE/deps
|
||||
export CC="$TARGET-gcc"
|
||||
@@ -97,11 +99,20 @@ jobs:
|
||||
export STRIP=$TARGET-strip
|
||||
export PKG_CONFIG_PATH=$DEPS_DIR/lib/pkgconfig
|
||||
export STAGING_DIR=$RUNNER_TEMP
|
||||
if [ "$ARCH" = lexra ]; then
|
||||
OPTIMIZE=-Os
|
||||
else
|
||||
OPTIMIZE=-Oz
|
||||
fi
|
||||
OPTIMIZE=-Oz
|
||||
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
|
||||
case "$ARCH" in
|
||||
lexra)
|
||||
OPTIMIZE=-Os
|
||||
;;
|
||||
arm)
|
||||
CPU="-mcpu=cortex-a7 -mthumb"
|
||||
;;
|
||||
arm64|mips64)
|
||||
# not safe without GC64
|
||||
SYSMALLOC=
|
||||
;;
|
||||
esac
|
||||
MINSIZE="$OPTIMIZE $MINSIZE"
|
||||
|
||||
if [[ "$ARCH" == lexra ]] || [[ "$ARCH" == riscv64 ]] || [[ "$ARCH" == x86 ]] ; then
|
||||
@@ -109,7 +120,7 @@ jobs:
|
||||
wget -qO- https://www.lua.org/ftp/lua-${LUA_RELEASE}.tar.gz | tar -xz
|
||||
(
|
||||
cd lua-${LUA_RELEASE}
|
||||
make CC=$CC AR="$AR rc" CFLAGS="$MINSIZE $CFLAGS" LDFLAGS="$LDMINSIZE $LDFLAGS" linux -j$(nproc)
|
||||
make CC=$CC AR="$AR rc" CFLAGS="$CPU $MINSIZE $CFLAGS" LDFLAGS="$LDMINSIZE $LDFLAGS" linux -j$(nproc)
|
||||
make install INSTALL_TOP=$DEPS_DIR INSTALL_BIN=$DEPS_DIR/bin INSTALL_INC=$DEPS_DIR/include/lua${LUA_VER} INSTALL_LIB=$DEPS_DIR/lib
|
||||
)
|
||||
LJIT=0
|
||||
@@ -125,9 +136,10 @@ jobs:
|
||||
*)
|
||||
HOSTCC="cc -m32"
|
||||
esac
|
||||
echo ARCH=$ARCH SYSMALLOC=$SYSMALLOC
|
||||
(
|
||||
cd luajit2-*
|
||||
make BUILDMODE=static XCFLAGS=-DLUAJIT_DISABLE_FFI HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" -j$(nproc)
|
||||
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS" -j$(nproc)
|
||||
make install PREFIX= DESTDIR=$DEPS_DIR
|
||||
)
|
||||
LJIT=1
|
||||
@@ -143,7 +155,7 @@ jobs:
|
||||
for i in libmnl libnfnetlink libnetfilter_queue ; do
|
||||
(
|
||||
cd $i-*
|
||||
CFLAGS="$MINSIZE $CFLAGS" \
|
||||
CFLAGS="$CPU $MINSIZE $CFLAGS" \
|
||||
LDFLAGS="$LDMINSIZE $LDFLAGS" \
|
||||
./configure --prefix= --host=$TARGET --enable-static --disable-shared --disable-dependency-tracking
|
||||
make install -j$(nproc) DESTDIR=$DEPS_DIR
|
||||
@@ -156,7 +168,7 @@ jobs:
|
||||
xargs -I{} wget -qO- https://github.com/madler/zlib/archive/refs/tags/{}.tar.gz | tar -xz
|
||||
(
|
||||
cd zlib-*
|
||||
CFLAGS="$MINSIZE $CFLAGS" \
|
||||
CFLAGS="$CPU $MINSIZE $CFLAGS" \
|
||||
./configure --prefix= --static
|
||||
make install -j$(nproc) DESTDIR=$DEPS_DIR
|
||||
)
|
||||
@@ -168,9 +180,9 @@ jobs:
|
||||
|
||||
# zapret2
|
||||
OPTIMIZE=$OPTIMIZE \
|
||||
CFLAGS="-DZAPRET_GH_VER=${{ github.ref_name }} -DZAPRET_GH_HASH=${{ github.sha }} -static-libgcc -static -I$DEPS_DIR/include $CFLAGS" \
|
||||
CFLAGS="-DZAPRET_GH_VER=${{ github.ref_name }} -DZAPRET_GH_HASH=${{ github.sha }} -static-libgcc -I$DEPS_DIR/include $CPU $CFLAGS" \
|
||||
LDFLAGS="-L$DEPS_DIR/lib $LDFLAGS" \
|
||||
make -C zapret2 LUA_JIT=$LJIT LUA_CFLAGS="$LCFLAGS" LUA_LIB="$LLIB" -j$(nproc)
|
||||
make -C zapret2 CFLAGS_PIC= LDFLAGS_PIE=-static LUA_JIT=$LJIT LUA_CFLAGS="$LCFLAGS" LUA_LIB="$LLIB" -j$(nproc)
|
||||
|
||||
tar -C zapret2/binaries/my -cJf zapret2-linux-$ARCH.tar.xz .
|
||||
|
||||
@@ -230,6 +242,16 @@ jobs:
|
||||
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
|
||||
export STRIP=$TOOLCHAIN/bin/llvm-strip
|
||||
export PKG_CONFIG_PATH=$DEPS_DIR/lib/pkgconfig
|
||||
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
|
||||
case "$ABI" in
|
||||
armeabi-v7a)
|
||||
CPU="-mthumb"
|
||||
;;
|
||||
arm64-v8a)
|
||||
# not safe without GC64
|
||||
SYSMALLOC=
|
||||
;;
|
||||
esac
|
||||
|
||||
# luajit
|
||||
wget -qO- https://github.com/openresty/luajit2/archive/refs/tags/v${LUAJIT_RELEASE}.tar.gz | tar -xz
|
||||
@@ -242,7 +264,7 @@ jobs:
|
||||
esac
|
||||
(
|
||||
cd luajit2-*
|
||||
make BUILDMODE=static XCFLAGS=-DLUAJIT_DISABLE_FFI HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" -j$(nproc)
|
||||
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC="$HOSTCC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$CPU $MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" -j$(nproc)
|
||||
make install PREFIX= DESTDIR=$DEPS_DIR
|
||||
)
|
||||
LJIT=1
|
||||
@@ -258,7 +280,7 @@ jobs:
|
||||
for i in libmnl libnfnetlink libnetfilter_queue ; do
|
||||
(
|
||||
cd $i-*
|
||||
CFLAGS="$MINSIZE -Wno-implicit-function-declaration $CFLAGS" \
|
||||
CFLAGS="$CPU $MINSIZE -Wno-implicit-function-declaration $CFLAGS" \
|
||||
LDFLAGS="$LDMINSIZE $LDFLAGS" \
|
||||
./configure --prefix= --host=$TARGET --enable-static --disable-shared --disable-dependency-tracking
|
||||
make install -j$(nproc) DESTDIR=$DEPS_DIR
|
||||
@@ -267,7 +289,7 @@ jobs:
|
||||
done
|
||||
|
||||
# zapret2
|
||||
CFLAGS="-DZAPRET_GH_VER=${{ github.ref_name }} -DZAPRET_GH_HASH=${{ github.sha }} -I$DEPS_DIR/include" \
|
||||
CFLAGS="-DZAPRET_GH_VER=${{ github.ref_name }} -DZAPRET_GH_HASH=${{ github.sha }} -I$DEPS_DIR/include $CPU" \
|
||||
LDFLAGS="-L$DEPS_DIR/lib" \
|
||||
make -C zapret2 LUA_JIT=$LJIT LUA_CFLAGS="$LCFLAGS" LUA_LIB="$LLIB" -j$(nproc) android
|
||||
|
||||
@@ -314,15 +336,16 @@ jobs:
|
||||
env:
|
||||
TARGET: ${{ matrix.target }}
|
||||
ARCH: ${{ matrix.arch }}
|
||||
PIC: -fpic
|
||||
CC: ${{ matrix.target }}-freebsd11-clang
|
||||
MINSIZE: -Oz -flto=auto -ffunction-sections -fdata-sections
|
||||
MINSIZE: -Os -flto=auto -ffunction-sections -fdata-sections
|
||||
LDMINSIZE: -Wl,--gc-sections -flto=auto
|
||||
run: |
|
||||
|
||||
wget -qO- https://github.com/openresty/luajit2/archive/refs/tags/v${LUAJIT_RELEASE}.tar.gz | tar -xz
|
||||
(
|
||||
cd luajit2-*
|
||||
make BUILDMODE=static XCFLAGS=-DLUAJIT_DISABLE_FFI HOST_CC=gcc CC=$CC TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS"
|
||||
make BUILDMODE=static XCFLAGS="$PIC -DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_FFI" HOST_CC=gcc CC=$CC TARGET_CFLAGS="$MINSIZE $CFLAGS $PIC" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS"
|
||||
make install PREFIX= DESTDIR=$DEPS_DIR
|
||||
)
|
||||
|
||||
@@ -435,7 +458,7 @@ jobs:
|
||||
wget -q https://github.com/openresty/luajit2/archive/refs/tags/v${LUAJIT_RELEASE}.tar.gz &&
|
||||
tar -xzf v${LUAJIT_RELEASE}.tar.gz &&
|
||||
rm -f v${LUAJIT_RELEASE}.tar.gz &&
|
||||
make -C luajit2-${LUAJIT_RELEASE} BUILDMODE=static XCFLAGS="-DLUAJIT_DISABLE_FFI -ffat-lto-objects" TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" &&
|
||||
make -C luajit2-${LUAJIT_RELEASE} BUILDMODE=static XCFLAGS="-DLUAJIT_USE_SYSMALLOC -DLUAJIT_DISABLE_FFI -ffat-lto-objects" TARGET_CFLAGS="$MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS" &&
|
||||
make -C luajit2-${LUAJIT_RELEASE} install
|
||||
|
||||
- name: Build winws
|
||||
@@ -458,6 +481,8 @@ jobs:
|
||||
cp -a -t output psmisc/psmisc-*.src/psmisc-*/inst/usr/bin/killall.exe /usr/bin/cygwin1.dll &&
|
||||
wget -O WinDivert.zip https://github.com/basil00/WinDivert/releases/download/v2.2.2/WinDivert-2.2.2-A.zip &&
|
||||
unzip -j WinDivert.zip "*/${DIR}/WinDivert.dll" "*/${DIR}/WinDivert${BITS}.sys" -d output &&
|
||||
( [ "$BITS" = 64 ] && rebase -b 0x205c00000 output/WinDivert.dll || true ) &&
|
||||
peflags --dynamicbase=true --high-entropy-va=true output/WinDivert.dll &&
|
||||
zip zapret2-win-${{ matrix.arch }}.zip -j output/*
|
||||
|
||||
- name: Upload artifacts
|
||||
|
||||
@@ -438,6 +438,13 @@ has_bad_ws_options()
|
||||
echo "Kernel ipsets should be used instead. Write custom scripts and filter IPs in kernel."
|
||||
echo
|
||||
}
|
||||
contains "$1" "--ipset=$ZAPRET_BASE" || contains "$1" "--ipset-exclude=$ZAPRET_BASE" ||
|
||||
contains "$1" "--hostlist=$ZAPRET_BASE" || contains "$1" "--hostlist-exclude=$ZAPRET_BASE" && {
|
||||
echo
|
||||
echo "WARNING !!! you store ipset or hostlist files inside '$ZAPRET_BASE'"
|
||||
echo "It's not recommended. install_easy.sh will delete them during update."
|
||||
echo
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -259,3 +259,16 @@ v0.9.4.3
|
||||
* nfqws2: fix broken wifi ssid update
|
||||
* github: revert to upx 4.2.4 for all archs except riscv64
|
||||
* zapret-lib: apply_fooling throws error if tcp_ts,tcp_seq,tcp_ack,ip_ttl,ip6_ttl,ip_autottl,ip6_autottl are empty or invalid
|
||||
|
||||
0.9.4.4
|
||||
|
||||
* winws2, dvtws2: ASLR
|
||||
* github, linux-builder: reduce arm executable size by 20% - move to armv7+thumb
|
||||
* init.d: warn if hostlist/ipset files are inside zapret2 root
|
||||
* zapret-lib: do not call apply_arg_prefix in apply_execution_plan - call it right before instance execute
|
||||
|
||||
0.9.4.5
|
||||
|
||||
* github: rollback to lj_alloc in luajit for arm64 and mips64
|
||||
* nfqws2: join fragments in quic CRYPTO reconstruction. allow intersections.
|
||||
|
||||
|
||||
@@ -61,10 +61,21 @@ build_lua()
|
||||
}
|
||||
build_luajit()
|
||||
{
|
||||
local CFL="$CFLAGS"
|
||||
local SYSMALLOC=
|
||||
(
|
||||
cd luajit2-*
|
||||
CFLAGS="-Os"
|
||||
make clean
|
||||
make BUILDMODE=static XCFLAGS=-DLUAJIT_DISABLE_FFI HOST_CC="$HOST_CC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$OPTIMIZE $MINSIZE $CFLAGS" TARGET_LDFLAGS="$LDMINSIZE $LDFLAGS"
|
||||
case $TARGET in
|
||||
aarch64*|mips64*)
|
||||
# sysmalloc can cause troubles without GC64. GC64 slows down by 10-15%. better not to use sysmalloc and leave lj_alloc.
|
||||
;;
|
||||
*)
|
||||
# save some exe size
|
||||
SYSMALLOC=-DLUAJIT_USE_SYSMALLOC
|
||||
esac
|
||||
make BUILDMODE=static XCFLAGS="$SYSMALLOC -DLUAJIT_DISABLE_FFI $CFLAGS_PIC" HOST_CC="$HOST_CC" CROSS= CC="$CC" TARGET_AR="$AR rcus" TARGET_STRIP=$STRIP TARGET_CFLAGS="$OPTIMIZE $MINSIZE $CFL" TARGET_LDFLAGS="$CPU $LDMINSIZE $LDFLAGS"
|
||||
make install PREFIX= DESTDIR="$STAGING_DIR"
|
||||
)
|
||||
}
|
||||
@@ -89,8 +100,11 @@ dl_deps
|
||||
check_toolchains
|
||||
ask_target
|
||||
|
||||
CFLAGS_BASE="$CFLAGS"
|
||||
for t in $TGT; do
|
||||
CFLAGS="$CFLAGS_BASE"
|
||||
buildenv $t
|
||||
CFLAGS="$CFLAGS $CFLAGS_PIC"
|
||||
pushd "$DEPS"
|
||||
install_h_files
|
||||
build_netlink
|
||||
|
||||
@@ -36,7 +36,9 @@ ask_target
|
||||
|
||||
[ -d "$ZBIN" ] || mkdir -p "$ZBIN"
|
||||
|
||||
CFLAGS_BASE="$CFLAGS"
|
||||
for t in $TGT; do
|
||||
CFLAGS="$CFLAGS_BASE $MINSIZE"
|
||||
buildenv $t
|
||||
|
||||
translate_target $t || {
|
||||
@@ -48,8 +50,8 @@ for t in $TGT; do
|
||||
|
||||
make clean
|
||||
OPTIMIZE=$OPTIMIZE \
|
||||
CFLAGS="-static-libgcc -static -I$STAGING_DIR/include $MINSIZE $CFLAGS" \
|
||||
LDFLAGS="-L$STAGING_DIR/lib $LDMINSIZE $LDFLAGS" \
|
||||
CFLAGS="-static-libgcc -I$STAGING_DIR/include $CFLAGS $CFLAGS_PIC" \
|
||||
LDFLAGS="-L$STAGING_DIR/lib $LDMINSIZE $LDFLAGS_PIE $LDFLAGS" \
|
||||
make
|
||||
|
||||
[ -d "$ZBIN/$ZBINTARGET" ] || mkdir "$ZBIN/$ZBINTARGET"
|
||||
|
||||
@@ -36,7 +36,9 @@ ask_target
|
||||
|
||||
[ -d "$ZBIN" ] || mkdir -p "$ZBIN"
|
||||
|
||||
CFLAGS_BASE="$CFLAGS"
|
||||
for t in $TGT; do
|
||||
CFLAGS="$CFLAGS_BASE"
|
||||
buildenv $t
|
||||
|
||||
translate_target $t || {
|
||||
@@ -59,9 +61,9 @@ for t in $TGT; do
|
||||
LUA_JIT=$LUA_JIT LUA_VER=$LUA_VER LUAJIT_LUA_VER=$LUAJIT_LUA_VER \
|
||||
OPTIMIZE=$OPTIMIZE \
|
||||
MINSIZE=$MINSIZE \
|
||||
CFLAGS="-static-libgcc -static -I$STAGING_DIR/include $CFLAGS" \
|
||||
CFLAGS="-static-libgcc -I$STAGING_DIR/include $CFLAGS" \
|
||||
LDFLAGS="-L$STAGING_DIR/lib $LDFLAGS" \
|
||||
make LUA_JIT=$LJIT LUA_CFLAGS="$LCFLAGS" LUA_LIB="$LLIB"
|
||||
make CFLAGS_PIC="$CFLAGS_PIC" LDFLAGS_PIE="$LDFLAGS_PIE" LUA_JIT=$LJIT LUA_CFLAGS="$LCFLAGS" LUA_LIB="$LLIB"
|
||||
|
||||
[ -d "$ZBIN/$ZBINTARGET" ] || mkdir "$ZBIN/$ZBINTARGET"
|
||||
cp -f binaries/my/* "$ZBIN/$ZBINTARGET"
|
||||
|
||||
@@ -5,10 +5,14 @@ TOOLCHAINS="$EXEDIR/toolchain"
|
||||
DEPS="$EXEDIR/deps"
|
||||
STAGE="$EXEDIR/staging"
|
||||
OPTIMIZE=${OPTIMIZE:--Oz}
|
||||
MINSIZE="${MINSIZE:--flto=auto -ffunction-sections -fdata-sections}"
|
||||
#MINSIZE="${MINSIZE:--flto=auto -ffunction-sections -fdata-sections}"
|
||||
MINSIZE="${MINSIZE:--ffunction-sections -fdata-sections}"
|
||||
LDMINSIZE="${LDMINSIZE:--Wl,--gc-sections -flto=auto}"
|
||||
#CFLAGS=""
|
||||
LDFLAGS="-lgcc_eh $LDFLAGS"
|
||||
# PIE makes ASLR working but adds 5% to size
|
||||
# PIE does not work for arm32 and all mips
|
||||
PIE=${PIE:-0}
|
||||
HOSTCC=${HOSTCC:-cc}
|
||||
LUA_VER=${LUA_VER:-5.5}
|
||||
LUA_RELEASE=${LUA_RELEASE:-5.5.0}
|
||||
@@ -19,7 +23,7 @@ nproc=$(nproc)
|
||||
|
||||
TARGETS="\
|
||||
aarch64-unknown-linux-musl \
|
||||
arm-unknown-linux-musleabi \
|
||||
armv6-unknown-linux-musleabi \
|
||||
i586-unknown-linux-musl \
|
||||
x86_64-unknown-linux-musl \
|
||||
mips-unknown-linux-muslsf \
|
||||
@@ -34,7 +38,7 @@ target_has_luajit()
|
||||
{
|
||||
case "$1" in
|
||||
aarch64-unknown-linux-musl| \
|
||||
arm-unknown-linux-musleabi| \
|
||||
armv6-unknown-linux-musleabi| \
|
||||
x86_64-unknown-linux-musl| \
|
||||
mips-unknown-linux-muslsf| \
|
||||
mips64-unknown-linux-musl| \
|
||||
@@ -89,7 +93,27 @@ buildenv()
|
||||
export PKG_CONFIG_PATH=$STAGING_DIR/lib/pkgconfig
|
||||
OLDPATH="$PATH"
|
||||
export PATH="$PATH:$TOOLCHAINS/$TARGET/bin"
|
||||
|
||||
CPU=
|
||||
CFLAGS_PIC=
|
||||
LDFLAGS_PIE=-static
|
||||
# not all archs support -static-pie. if does not support - it produces dynamic executable
|
||||
# "-static -static-pie" causes segfaults
|
||||
case $1 in
|
||||
armv6-*)
|
||||
CPU="-mthumb -msoft-float"
|
||||
CFLAGS="$CPU $CFLAGS"
|
||||
;;
|
||||
mips*)
|
||||
;;
|
||||
*)
|
||||
[ "$PIE" = 1 ] && {
|
||||
CFLAGS_PIC=-fPIC
|
||||
LDFLAGS_PIE="-static-pie"
|
||||
}
|
||||
esac
|
||||
}
|
||||
|
||||
buildenv_clear()
|
||||
{
|
||||
export PATH="$OLDPATH" TARGET= CC= LD= AR= NM= STRIP= STAGING_DIR= PKG_CONFIG_PATH=
|
||||
@@ -249,7 +273,7 @@ translate_target()
|
||||
aarch64-unknown-linux-musl)
|
||||
ZBINTARGET=linux-arm64
|
||||
;;
|
||||
arm-unknown-linux-musleabi)
|
||||
armv6-unknown-linux-musleabi)
|
||||
ZBINTARGET=linux-arm
|
||||
;;
|
||||
x86_64-unknown-linux-musl)
|
||||
|
||||
@@ -3531,7 +3531,8 @@ Checks the [instance cutoff](#instance_cutoff) state for `desync.func_instance`
|
||||
function apply_arg_prefix(desync)
|
||||
```
|
||||
|
||||
Performs substitution of argument values from `desync.arg` that start with `%` and `#`.
|
||||
Performs substitution of argument values from `desync.arg` that start with `%`, `#`, `\`.
|
||||
Multiple calls are safe but do not update desync.arg if blobs were changed.
|
||||
|
||||
### apply_execution_plan
|
||||
|
||||
@@ -3540,6 +3541,8 @@ function apply_execution_plan(desync, instance)
|
||||
```
|
||||
|
||||
Copies the instance identification and its arguments from an [execution plan](#execution_plan) `instance` into the desync object, thereby recreating the desync state as if the `instance` were called directly by C code.
|
||||
With one exception : apply_arg_prefix is not applied because args can refer a blob created by previous conditionally executed instances.
|
||||
|
||||
The [execution plan](#execution_plan) is provided by the C function `execution_plan()` as an array of `instance` elements.
|
||||
|
||||
### verdict_aggregate
|
||||
@@ -3558,6 +3561,7 @@ function plan_instance_execute_preapplied(desync, verdict, instance)
|
||||
```
|
||||
|
||||
Executes an [execution plan](#execution_plan) `instance`, taking into account the [instance cutoff](#instance_cutoff) and standard [payload](#in-profile-filters) and [range](#in-profile-filters) filters.
|
||||
Calls apply_arg_prefix right before calling the instance.
|
||||
Returns the aggregation of the current verdict and the `instance` verdict.
|
||||
|
||||
The "preapplied" version does not apply execution plan, allowing the calling code to do so.
|
||||
@@ -4479,6 +4483,7 @@ function cond_lua(desync)
|
||||
```
|
||||
|
||||
Executes a Lua code from the "cond_code" argument. The code returns condition value. Direct addressing of the desync table is possible within the code.
|
||||
desync.arg is passed without called "apply_arg_prefix" : `%`, `#`, `\` remain as is without substitution because can refer blobs created by previous conditionally executed instances.
|
||||
|
||||
|
||||
# Auxiliary programs
|
||||
|
||||
@@ -3709,7 +3709,8 @@ function cutoff_shim_check(desync)
|
||||
function apply_arg_prefix(desync)
|
||||
```
|
||||
|
||||
Выполняет подстановку значений аргументов из desync.arg, начинающихся с `%` и `#`.
|
||||
Выполняет подстановку значений аргументов из desync.arg, начинающихся с `%` и `#`, `\`.
|
||||
Функция ставит специальную метку в desync.arg , чтобы избежать двойного разименования. Повторные вызовы безопасны, но не обновляют desync.arg при изменении блобов.
|
||||
|
||||
### apply_execution_plan
|
||||
|
||||
@@ -3719,6 +3720,8 @@ function apply_execution_plan(desync, instance)
|
||||
|
||||
Копирует в desync идентификацию инстанса и его аргументы из элемента [execution plan](#execution_plan) `instance`,
|
||||
тем самым воссоздает состояние desync, как если бы `instance` был вызван напрямую C кодом.
|
||||
За одним исключением : apply_arg_prefix не применяется, поскольку может содержать несуществующие блоб, существование которого зависит от условного выполнения предыдущих истансов.
|
||||
|
||||
[execution plan](#execution_plan) выдается C функцией `execution_plan()` как массив, элементами которого являются `instance`.
|
||||
|
||||
### verdict_aggregate
|
||||
@@ -3737,6 +3740,7 @@ function plan_instance_execute_preapplied(desync, verdict, instance)
|
||||
```
|
||||
|
||||
Выполняет элемент [execution plan](#execution_plan) `instance` с учетом [instance cutoff](#instance_cutoff) и стандартных фильтров [payload](#внутрипрофильные-фильтры) и [range](#внутрипрофильные-фильтры).
|
||||
При совпадении условий непосредственно перед вызовом выполняет apply_arg_prefix.
|
||||
Возвращает агрегацию verdict и вердикта `instance`.
|
||||
|
||||
Вариант "preapplied" не выполняет apply_execution_plan, позволяя это сделат вызывающему коду.
|
||||
@@ -4658,6 +4662,7 @@ function cond_lua(desync)
|
||||
```
|
||||
|
||||
Выполняет Lua код из аргумента "cond_code". Код возвращает значение условия через return. Возможна прямая адресация таблицы desync.
|
||||
desync.arg передаются с НЕ разименованными `%`, `#`, `\`, поскольку разименование может ссылаться на блобы, создаваемые предыдущими условно вызываемыми инстансами.
|
||||
|
||||
# Вспомогательные программы
|
||||
|
||||
|
||||
@@ -414,8 +414,8 @@ nfqws2 \
|
||||
### Какие есть еще параметры
|
||||
|
||||
Как узнать какие есть еще функции и какие у них бывают параметры ? Смотрите `zapret-antidpi.lua`. Перед каждой функцией подробно описано какие параметры она берет.
|
||||
Описание стандартных блоков параметров есть в начале. Позже - по мере сил и возможностей - будет писаться талмуд - справочник с руководством по программированию
|
||||
*nfqws2* и описание стандартных библиотек.
|
||||
Описание стандартных блоков параметров есть в начале.
|
||||
Или сразу читайте [талмуд](manual.md) . Там все документировано.
|
||||
|
||||
### Очень важный совет
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ Type=forking
|
||||
Restart=no
|
||||
TimeoutSec=30sec
|
||||
IgnoreSIGPIPE=no
|
||||
KillMode=none
|
||||
GuessMainPID=no
|
||||
RemainAfterExit=no
|
||||
ExecStart=/opt/zapret2/init.d/sysv/zapret2 start
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
CC ?= cc
|
||||
OPTIMIZE ?= -Os
|
||||
CFLAGS += -std=gnu99 $(OPTIMIZE) -flto=auto
|
||||
CFLAGS_PIC = -fPIC
|
||||
CFLAGS += -std=gnu99 $(OPTIMIZE) -flto=auto $(CFLAGS_PIC)
|
||||
CFLAGS_BSD = -Wno-address-of-packed-member
|
||||
CFLAGS_WIN = -static
|
||||
LDFLAGS_PIE = -pie
|
||||
LDFLAGS += $(LDFLAGS_PIE)
|
||||
|
||||
LIBS =
|
||||
LIBS_WIN = -lws2_32
|
||||
SRC_FILES = ip2net.c qsort.c
|
||||
|
||||
@@ -125,7 +125,7 @@ function http_domcase(ctx, desync)
|
||||
local host_range = resolve_multi_pos(desync.dis.payload,desync.l7payload,"host,endhost")
|
||||
if #host_range == 2 then
|
||||
local host = string.sub(desync.dis.payload,host_range[1],host_range[2]-1)
|
||||
local newhost="", i
|
||||
local newhost=""
|
||||
for i = 1, #host do
|
||||
newhost=newhost..((i%2)==0 and string.lower(string.sub(host,i,i)) or string.upper(string.sub(host,i,i)))
|
||||
end
|
||||
@@ -221,7 +221,7 @@ function http_unixeol(ctx, desync)
|
||||
if #http < #desync.dis.payload then
|
||||
hdis.headers[idx_ua].value = hdis.headers[idx_ua].value .. string.rep(" ", #desync.dis.payload - #http)
|
||||
end
|
||||
local http = http_reconstruct_req(hdis, true)
|
||||
http = http_reconstruct_req(hdis, true)
|
||||
if #http==#desync.dis.payload then
|
||||
desync.dis.payload = http
|
||||
DLOG("http_unixeol: applied")
|
||||
@@ -894,7 +894,7 @@ function fakedsplit(ctx, desync)
|
||||
return desync.arg.nodrop and VERDICT_PASS or VERDICT_DROP
|
||||
end
|
||||
else
|
||||
DLOG("fakedsplit: cannot resolve pos '"..desync.arg.pos.."'")
|
||||
DLOG("fakedsplit: cannot resolve pos '"..spos.."'")
|
||||
end
|
||||
else
|
||||
DLOG("fakedsplit: not acting on further replay pieces")
|
||||
@@ -939,7 +939,7 @@ function fakeddisorder(ctx, desync)
|
||||
if b_debug then DLOG("fakeddisorder: resolved split pos: "..tostring(pos-1)) end
|
||||
|
||||
-- do not apply fooling to original parts except tcp_ts_up but apply ip_id
|
||||
local fake, part, pat
|
||||
local fake, part
|
||||
local opts_orig = {rawsend = rawsend_opts_base(desync), reconstruct = {}, ipfrag = {}, ipid = desync.arg, fooling = {tcp_ts_up = desync.arg.tcp_ts_up}}
|
||||
local opts_fake = {rawsend = rawsend_opts(desync), reconstruct = reconstruct_opts(desync), ipfrag = {}, ipid = desync.arg, fooling = desync.arg}
|
||||
|
||||
@@ -1009,7 +1009,7 @@ function fakeddisorder(ctx, desync)
|
||||
return desync.arg.nodrop and VERDICT_PASS or VERDICT_DROP
|
||||
end
|
||||
else
|
||||
DLOG("fakeddisorder: cannot resolve pos '"..desync.arg.pos.."'")
|
||||
DLOG("fakeddisorder: cannot resolve pos '"..spos.."'")
|
||||
end
|
||||
else
|
||||
DLOG("fakeddisorder: not acting on further replay pieces")
|
||||
@@ -1210,8 +1210,8 @@ function udplen(ctx, desync)
|
||||
else
|
||||
desync.dis.payload = string.sub(desync.dis.payload,1,len+inc)
|
||||
DLOG("udplen: "..len.." => "..#desync.dis.payload)
|
||||
return VERDICT_MODIFY
|
||||
end
|
||||
return VERDICT_MODIFY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -313,7 +313,7 @@ function circular(ctx, desync)
|
||||
local function count_strategies(hrec)
|
||||
if not hrec.ctstrategy then
|
||||
local uniq={}
|
||||
local n=0
|
||||
local n
|
||||
for i,instance in pairs(desync.plan) do
|
||||
if instance.arg.strategy then
|
||||
n = tonumber(instance.arg.strategy)
|
||||
|
||||
@@ -98,10 +98,10 @@ function detect_payload_str(ctx, desync)
|
||||
local data = desync.reasm_data or desync.dis.payload
|
||||
local b = data and string.find(data,desync.arg.pattern,1,true)
|
||||
if b then
|
||||
DLOG("detect_payload_str: detected '"..desync.arg.payload.."'")
|
||||
DLOG("detect_payload_str: detected '"..(desync.arg.payload or '?').."'")
|
||||
if desync.arg.payload then desync.l7payload = desync.arg.payload end
|
||||
else
|
||||
DLOG("detect_payload_str: not detected '"..desync.arg.payload.."'")
|
||||
DLOG("detect_payload_str: not detected '"..(desync.arg.payload or '?').."'")
|
||||
if desync.arg.undetected then desync.l7payload = desync.arg.undetected end
|
||||
end
|
||||
end
|
||||
@@ -149,11 +149,13 @@ end
|
||||
|
||||
-- applies # and $ prefixes. #var means var length, %var means var value
|
||||
function apply_arg_prefix(desync)
|
||||
-- prevent double apply
|
||||
if desync.arg.__prefix_applied then return end
|
||||
for a,v in pairs(desync.arg) do
|
||||
local c = string.sub(v,1,1)
|
||||
if c=='#' then
|
||||
local blb = blob(desync,string.sub(v,2))
|
||||
desync.arg[a] = tostring((type(blb)=='string' or type(blb)=='table') and #blb or 0)
|
||||
desync.arg[a] = tostring(type(blb)=='string' and #blb or 0)
|
||||
elseif c=='%' then
|
||||
desync.arg[a] = blob(desync,string.sub(v,2))
|
||||
elseif c=='\\' then
|
||||
@@ -163,6 +165,7 @@ function apply_arg_prefix(desync)
|
||||
end
|
||||
end
|
||||
end
|
||||
desync.arg.__prefix_applied = true
|
||||
end
|
||||
-- copy instance identification and args from execution plan to desync table
|
||||
-- NOTE : to not lose VERDICT_MODIFY dissect changes pass original desync table
|
||||
@@ -173,7 +176,7 @@ function apply_execution_plan(desync, instance)
|
||||
desync.func_n = instance.func_n
|
||||
desync.func_instance = instance.func_instance
|
||||
desync.arg = deepcopy(instance.arg)
|
||||
apply_arg_prefix(desync)
|
||||
-- no apply_arg_prefix here because it may refer non-existing blobs
|
||||
end
|
||||
-- produce resulting verdict from 2 verdicts
|
||||
function verdict_aggregate(v1, v2)
|
||||
@@ -200,6 +203,9 @@ function plan_instance_execute_preapplied(desync, verdict, instance)
|
||||
elseif not pos_check_range(desync, instance.range) then
|
||||
DLOG("plan_instance_execute: not calling '"..desync.func_instance.."' because pos "..pos_str(desync,instance.range.from).." "..pos_str(desync,instance.range.to).." is out of range '"..pos_range_str(instance.range).."'")
|
||||
else
|
||||
-- condition is satisfied. here blobs must be referenced
|
||||
apply_arg_prefix(desync)
|
||||
desync.arg.__prefix_applied = nil
|
||||
DLOG("plan_instance_execute: calling '"..desync.func_instance.."'")
|
||||
verdict = verdict_aggregate(verdict,_G[instance.func](nil, desync))
|
||||
end
|
||||
@@ -632,7 +638,7 @@ function tls_mod_shim(desync, blob, modlist, payload)
|
||||
if not val then
|
||||
error("tls_mod_shim: non-existent var '"..var.."'")
|
||||
end
|
||||
modlist = string.sub(modlist,1,p1+3)..val..string.sub(modlist,p2+1)
|
||||
modlist = string.sub(modlist,1,p1+3)..tostring(val)..string.sub(modlist,p2+1)
|
||||
end
|
||||
return tls_mod(blob,modlist,payload)
|
||||
end
|
||||
@@ -644,7 +650,7 @@ function parse_tcp_flags(s)
|
||||
local s_upper = string.upper(s)
|
||||
for flag in string.gmatch(s_upper, "[^,]+") do
|
||||
if flags[flag] then
|
||||
f = bitor(f,flags[flag])
|
||||
f = bitor(f,flags[flag])
|
||||
else
|
||||
error("tcp flag '"..flag.."' is invalid")
|
||||
end
|
||||
@@ -875,7 +881,7 @@ function apply_fooling(desync, dis, fooling_options)
|
||||
if type(desync.track.lua_state.autottl_cache)~="table" then desync.track.lua_state.autottl_cache={} end
|
||||
if type(desync.track.lua_state.autottl_cache[desync.func_instance])~="table" then desync.track.lua_state.autottl_cache[desync.func_instance]={} end
|
||||
if not desync.track.lua_state.autottl_cache[desync.func_instance].autottl_found then
|
||||
attl = parse_autottl(arg_autottl)
|
||||
local attl = parse_autottl(arg_autottl)
|
||||
if not attl then
|
||||
error("apply_fooling: invalid autottl value '"..arg_autottl.."'")
|
||||
end
|
||||
@@ -962,7 +968,7 @@ function apply_fooling(desync, dis, fooling_options)
|
||||
end
|
||||
end
|
||||
if fooling_options.tcp_ts_up then
|
||||
move_ts_top(dis.tcp.options)
|
||||
move_ts_top()
|
||||
end
|
||||
end
|
||||
if dis.ip6 then
|
||||
@@ -1201,7 +1207,7 @@ function rawsend_dissect_segmented(desync, dis, mss, options)
|
||||
-- stop if failed
|
||||
return false
|
||||
end
|
||||
discopy.tcp.th_seq = discopy.tcp.th_seq + len
|
||||
discopy.tcp.th_seq = u32add(discopy.tcp.th_seq, len)
|
||||
pos = pos + len
|
||||
end
|
||||
return true
|
||||
@@ -1566,11 +1572,11 @@ function tls_client_hello_mod(tls, options)
|
||||
table.insert(tdis.handshake[TLS_HANDSHAKE_TYPE_CLIENT].dis.ext[idx_sni].dis.list, { name = options.sni_last, type = options.sni_snt_new } )
|
||||
end
|
||||
end
|
||||
local tls = tls_reconstruct(tdis)
|
||||
if not tls then
|
||||
local rtls = tls_reconstruct(tdis)
|
||||
if not rtls then
|
||||
DLOG_ERR("tls_client_hello_mod: reconstruct error")
|
||||
end
|
||||
return tls
|
||||
return rtls
|
||||
end
|
||||
|
||||
-- checks if filename is gzip compressed
|
||||
@@ -1659,7 +1665,7 @@ function readfile(filename)
|
||||
if not f then
|
||||
error("readfile: "..err)
|
||||
end
|
||||
local s,err = f:read("*a")
|
||||
local s, err = f:read("*a")
|
||||
f:close()
|
||||
if err then
|
||||
error("readfile: "..err)
|
||||
@@ -1677,7 +1683,7 @@ function writefile(filename, data)
|
||||
if not f then
|
||||
error("writefile: "..err)
|
||||
end
|
||||
local s,err = f:write(data)
|
||||
local s, err = f:write(data)
|
||||
f:close()
|
||||
if not s then
|
||||
error("writefile: "..err)
|
||||
@@ -1697,7 +1703,7 @@ function http_dissect_header(header)
|
||||
end
|
||||
-- make table with structured http header representation
|
||||
function http_dissect_headers(http, pos)
|
||||
local eol,pnext,header,value,idx,headers,pos_endheader,pos_startvalue,pos_headers_end
|
||||
local eol,pnext,header,value,headers,pos_endheader,pos_startvalue,pos_headers_end
|
||||
headers={}
|
||||
while pos do
|
||||
eol,pnext = find_next_line(http,pos)
|
||||
@@ -2261,7 +2267,8 @@ function tls_dissect_ext(ext)
|
||||
return left, off
|
||||
end
|
||||
|
||||
local dis={}, off, len, left
|
||||
local dis={}
|
||||
local off, len, left
|
||||
|
||||
ext.dis = nil
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ function test_aes()
|
||||
print("* aes")
|
||||
|
||||
local clear_text="test "..brandom_az09(11)
|
||||
local iv, key, encrypted, decrypted
|
||||
local encrypted, decrypted
|
||||
|
||||
for key_size=16,32,8 do
|
||||
local key = brandom(key_size)
|
||||
@@ -507,7 +507,7 @@ end
|
||||
function test_dissect()
|
||||
print("* dissect")
|
||||
|
||||
local dis, raw1, raw2
|
||||
local raw1, raw2
|
||||
|
||||
for i=1,20 do
|
||||
print("* dissect test "..tostring(i))
|
||||
@@ -611,7 +611,7 @@ function test_dissect()
|
||||
},
|
||||
payload = brandom(math.random(0, 20))
|
||||
}
|
||||
|
||||
|
||||
raw1 = reconstruct_dissect(ip6_udp)
|
||||
print("IP6+UDP : "..string2hex(raw1))
|
||||
dis1 = dissect(raw1)
|
||||
@@ -772,11 +772,6 @@ function test_csum()
|
||||
uh_ulen = UDP_BASE_LEN + #payload
|
||||
}
|
||||
|
||||
ip.ip_p = IPPROTO_UDP
|
||||
ip4b = reconstruct_iphdr(ip)
|
||||
ip6.ip6_plen = packet_len({ip6=ip6,udp=udp,payload=payload}) - IP6_BASE_LEN
|
||||
ip6b = reconstruct_ip6hdr(ip6, {ip6_last_proto=IPPROTO_UDP})
|
||||
|
||||
udpb = reconstruct_udphdr(udp)
|
||||
raw = bu16(udp.uh_sport) ..
|
||||
bu16(udp.uh_dport) ..
|
||||
@@ -785,8 +780,10 @@ function test_csum()
|
||||
print( raw==udpb and "UDP RECONSTRUCT OK" or "UDP RECONSTRUCT FAILED" )
|
||||
test_assert(raw==udpb)
|
||||
|
||||
ip.ip_p = IPPROTO_UDP
|
||||
raw = reconstruct_dissect({ip=ip, udp=udp, payload=payload})
|
||||
dis1 = dissect(raw)
|
||||
ip.ip_p = IPPROTO_UDP
|
||||
ip.ip_len = IP_BASE_LEN + #ip.options + #udpb + #payload
|
||||
ip4b = reconstruct_iphdr(ip)
|
||||
udpb = csum_udp_fix(ip4b,udpb,payload)
|
||||
@@ -794,6 +791,8 @@ function test_csum()
|
||||
print( dis1.udp.uh_sum==dis2.udp.uh_sum and "UDP+IP4 CSUM OK" or "UDP+IP4 CSUM FAILED" )
|
||||
test_assert(dis1.udp.uh_sum==dis2.udp.uh_sum)
|
||||
|
||||
ip6.ip6_plen = packet_len({ip6=ip6,udp=udp,payload=payload}) - IP6_BASE_LEN
|
||||
ip6b = reconstruct_ip6hdr(ip6, {ip6_last_proto=IPPROTO_UDP})
|
||||
raw = reconstruct_dissect({ip6=ip6, udp=udp, payload=payload})
|
||||
dis1 = dissect(raw)
|
||||
udpb = csum_udp_fix(ip6b,udpb,payload)
|
||||
@@ -949,7 +948,6 @@ function test_rawsend(opts)
|
||||
end
|
||||
local ip, ip6, udp, dis, ddis, raw_ip, raw_udp, raw
|
||||
local payload = brandom(math.random(100,1200))
|
||||
local b
|
||||
|
||||
local target
|
||||
for ifname,ifinfo in pairs(get_ifaddrs()) do
|
||||
@@ -997,7 +995,6 @@ function test_rawsend(opts)
|
||||
print("send ipv4 udp using pure rawsend without dissect")
|
||||
test_assert(rawsend_print(raw, {repeats=5}))
|
||||
|
||||
local target
|
||||
for ifname,ifinfo in pairs(get_ifaddrs()) do
|
||||
for k,v in pairs(ifinfo.addr) do
|
||||
if #v.addr==16 and (string.sub(v.addr,1,1)=="\xFC" or string.sub(v.addr,1,1)=="\xFD") then
|
||||
@@ -1083,7 +1080,7 @@ function test_rawsend(opts)
|
||||
print("send ipv6 icmp")
|
||||
test_assert(rawsend_dissect_print(dis, {fwmark = 0x8E10, repeats=3}))
|
||||
|
||||
local ip2 = {
|
||||
ip2 = {
|
||||
ip_tos = 0,
|
||||
ip_id = math.random(0,0xFFFF),
|
||||
ip_off = 0,
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
CC ?= cc
|
||||
OPTIMIZE ?= -Os
|
||||
CFLAGS += -std=gnu99 $(OPTIMIZE)
|
||||
CFLAGS_PIC = -fPIC
|
||||
CFLAGS += -std=gnu99 $(OPTIMIZE) $(CFLAGS_PIC)
|
||||
CFLAGS_BSD = -Wno-address-of-packed-member
|
||||
CFLAGS_WIN = -static
|
||||
LDFLAGS_PIE = -pie
|
||||
LDFLAGS += $(LDFLAGS_PIE)
|
||||
LIBS = -lpthread
|
||||
LIBS_ANDROID =
|
||||
LIBS_WIN = -lws2_32
|
||||
|
||||
@@ -2,8 +2,11 @@ CC ?= cc
|
||||
PKG_CONFIG ?= pkg-config
|
||||
OPTIMIZE ?= -Oz
|
||||
MINSIZE ?= -flto=auto -ffunction-sections -fdata-sections
|
||||
CFLAGS += -std=gnu99 -s $(OPTIMIZE) $(MINSIZE) -Wno-address-of-packed-member
|
||||
LDFLAGS += -flto=auto -Wl,--gc-sections
|
||||
STRIPP = -s
|
||||
CFLAGS_PIC = -fPIC
|
||||
CFLAGS += -std=gnu99 $(OPTIMIZE) $(MINSIZE) $(CFLAGS_PIC) -Wno-address-of-packed-member
|
||||
LDFLAGS_PIE = -pie
|
||||
LDFLAGS += -flto=auto -Wl,--gc-sections $(LDFLAGS_PIE)
|
||||
LIBS = -lz -lm
|
||||
SRC_FILES = *.c crypto/*.c
|
||||
|
||||
@@ -39,7 +42,7 @@ LUA_CFLAGS+=-DLUAJIT
|
||||
all: dvtws2
|
||||
|
||||
dvtws2: $(SRC_FILES)
|
||||
$(CC) $(CFLAGS) $(LUA_CFLAGS) -o dvtws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LDFLAGS)
|
||||
$(CC) $(STRIPP) $(CFLAGS) $(LUA_CFLAGS) -o dvtws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f dvtws2
|
||||
|
||||
@@ -3,14 +3,18 @@ PKG_CONFIG ?= pkg-config
|
||||
OPTIMIZE ?= -Os
|
||||
MINSIZE ?= -flto=auto -ffunction-sections -fdata-sections
|
||||
CFLAGS += -std=gnu99 $(OPTIMIZE) $(MINSIZE)
|
||||
CFLAGS_LINUX = -Wno-alloc-size-larger-than
|
||||
CFLAGS_PIC = -fPIC
|
||||
CFLAGS_LINUX = -Wno-alloc-size-larger-than $(CFLAGS_PIC)
|
||||
CFLAGS_SYSTEMD = -DUSE_SYSTEMD
|
||||
CFLAGS_BSD = -Wno-address-of-packed-member
|
||||
CFLAGS_CYGWIN = -Wno-address-of-packed-member -static
|
||||
CFLAGS_BSD = -Wno-address-of-packed-member $(CFLAGS_PIC)
|
||||
CFLAGS_CYGWIN = -Wno-address-of-packed-member -static -Wl,--nxcompat
|
||||
CFLAGS_CYGWIN32 =
|
||||
CFLAGS_CYGWIN64 = -Wl,--dynamicbase -Wl,--high-entropy-va
|
||||
CFLAGS_UBSAN = -fsanitize=undefined,alignment -fno-sanitize-recover=undefined,alignment
|
||||
LDFLAGS += -flto=auto -Wl,--gc-sections
|
||||
LDFLAGS_PIE = -pie
|
||||
LDFLAGS += -flto=auto -Wl,--gc-sections $(LDFLAGS_PIE)
|
||||
LDFLAGS_ANDROID = -llog
|
||||
STRIPP=-s
|
||||
LIBS =
|
||||
LIBS_LINUX = -lz -lnetfilter_queue -lnfnetlink -lmnl -lm
|
||||
LIBS_SYSTEMD = -lsystemd
|
||||
@@ -138,24 +142,24 @@ LUA_CFL += $(LUA_CFLAGS)
|
||||
all: nfqws2
|
||||
|
||||
nfqws2: $(SRC_FILES)
|
||||
$(CC) -s $(CFLAGS) $(LUA_CFL) $(CFLAGS_LINUX) -o nfqws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LIBS_LINUX) $(LDFLAGS)
|
||||
$(CC) $(STRIPP) $(CFLAGS) $(LUA_CFL) $(CFLAGS_LINUX) -o nfqws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LIBS_LINUX) $(LDFLAGS)
|
||||
|
||||
ubsan: $(SRC_FILES)
|
||||
$(CC) $(CFLAGS_UBSAN) $(CFLAGS) $(LUA_CFL) $(CFLAGS_LINUX) -o nfqws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LIBS_LINUX) $(LDFLAGS)
|
||||
|
||||
systemd: $(SRC_FILES)
|
||||
$(CC) -s $(CFLAGS) $(LUA_CFL) $(CFLAGS_LINUX) $(CFLAGS_SYSTEMD) -o nfqws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LIBS_LINUX) $(LIBS_SYSTEMD) $(LDFLAGS)
|
||||
$(CC) $(STRIPP) $(CFLAGS) $(LUA_CFL) $(CFLAGS_LINUX) $(CFLAGS_SYSTEMD) -o nfqws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LIBS_LINUX) $(LIBS_SYSTEMD) $(LDFLAGS)
|
||||
|
||||
android: $(SRC_FILES_ANDROID)
|
||||
$(CC) -s $(CFLAGS) $(LUA_CFL) -o nfqws2 $(SRC_FILES_ANDROID) $(LIBS) $(LUA_LIB) $(LIBS_LINUX) $(LDFLAGS) $(LDFLAGS_ANDROID)
|
||||
$(CC) $(STRIPP) $(CFLAGS) $(LUA_CFL) -o nfqws2 $(SRC_FILES_ANDROID) $(LIBS) $(LUA_LIB) $(LIBS_LINUX) $(LDFLAGS) $(LDFLAGS_ANDROID)
|
||||
|
||||
bsd: $(SRC_FILES)
|
||||
$(CC) -s $(CFLAGS) $(LUA_CFL) $(CFLAGS_BSD) -o dvtws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LIBS_BSD) $(LDFLAGS)
|
||||
$(CC) $(STRIPP) $(CFLAGS) $(LUA_CFL) $(CFLAGS_BSD) -o dvtws2 $(SRC_FILES) $(LIBS) $(LUA_LIB) $(LIBS_BSD) $(LDFLAGS)
|
||||
|
||||
cygwin64:
|
||||
$(CC) -s $(CFLAGS) $(LUA_CFL) $(CFLAGS_CYGWIN) -o winws2 $(SRC_FILES) $(RES_CYGWIN64) $(LIBS) $(LUA_LIB) $(LIBS_CYGWIN) $(LIBS_CYGWIN64) $(LDFLAGS)
|
||||
$(CC) $(STRIPP) $(CFLAGS) $(LUA_CFL) $(CFLAGS_CYGWIN) $(CFLAGS_CYGWIN64) -o winws2 $(SRC_FILES) $(RES_CYGWIN64) $(LIBS) $(LUA_LIB) $(LIBS_CYGWIN) $(LIBS_CYGWIN64) $(LDFLAGS)
|
||||
cygwin32:
|
||||
$(CC) -s $(CFLAGS) $(LUA_CFL) $(CFLAGS_CYGWIN) $(CFLAGS_CYGWIN32) -o winws2 $(SRC_FILES) $(RES_CYGWIN32) $(LIBS) $(LUA_LIB) $(LIBS_CYGWIN) $(LIBS_CYGWIN32) $(LDFLAGS)
|
||||
$(CC) $(STRIPP) $(CFLAGS) $(LUA_CFL) $(CFLAGS_CYGWIN) $(CFLAGS_CYGWIN32) -o winws2 $(SRC_FILES) $(RES_CYGWIN32) $(LIBS) $(LUA_LIB) $(LIBS_CYGWIN) $(LIBS_CYGWIN32) $(LDFLAGS)
|
||||
cygwin: cygwin64
|
||||
|
||||
clean:
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <basetsd.h>
|
||||
typedef unsigned int size_t;// use the right type for length declarations
|
||||
typedef UINT32 uint32_t;
|
||||
typedef UINT64 uint64_t;
|
||||
#else
|
||||
|
||||
@@ -803,8 +803,8 @@ static BOOL RemoveTokenPrivs(void)
|
||||
if (memcmp(&privs->Privileges[k].Luid, &luid_SeChangeNotifyPrivilege, sizeof(LUID)))
|
||||
privs->Privileges[k].Attributes = SE_PRIVILEGE_REMOVED;
|
||||
}
|
||||
bRes = AdjustTokenPrivileges(hToken, FALSE, privs, dwSize, NULL, NULL);
|
||||
}
|
||||
bRes = AdjustTokenPrivileges(hToken, FALSE, privs, dwSize, NULL, NULL);
|
||||
free(privs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2003,7 +2003,7 @@ static uint8_t dpi_desync_icmp_packet(
|
||||
// invert direction. they are answering to this packet
|
||||
bReverse = !bReverse;
|
||||
DLOG("found conntrack entry. inverted reverse=%u\n",bReverse);
|
||||
if (ctrack->dp_search_complete)
|
||||
if (ctrack->dp_search_complete && ctrack->dp)
|
||||
{
|
||||
// RELATED icmp processed within base connection profile
|
||||
dp = ctrack->dp;
|
||||
|
||||
@@ -50,7 +50,6 @@ void qsort_ssize_t(ssize_t *array, int ct)
|
||||
qsort(array, ct, sizeof(*array), cmp_ssize_t);
|
||||
}
|
||||
|
||||
|
||||
int str_index(const char **strs, int count, const char *str)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#define UNARY_PLUS(v) (v>0 ? "+" : "")
|
||||
//#define MIN(v1,v2) ((v1)<(v2) ? (v1) : (v2))
|
||||
//#define MAX(v1,v2) ((v1)<(v2) ? (v2) : (v1))
|
||||
|
||||
|
||||
// this saves memory. sockaddr_storage is larger than required. it can be 128 bytes. sockaddr_in6 is 28 bytes.
|
||||
typedef union
|
||||
|
||||
33
nfq2/lua.c
33
nfq2/lua.c
@@ -1868,7 +1868,7 @@ static bool lua_reconstruct_ip6exthdr(lua_State *L, int idx, struct ip6_hdr *ip6
|
||||
{
|
||||
LUA_STACK_GUARD_ENTER(L)
|
||||
// proto = last header type
|
||||
if (*len<sizeof(struct tcphdr)) return false;
|
||||
if (*len<sizeof(struct ip6_hdr)) return false;
|
||||
|
||||
uint8_t *last_proto = &ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
|
||||
size_t filled = sizeof(struct ip6_hdr);
|
||||
@@ -1905,11 +1905,24 @@ static bool lua_reconstruct_ip6exthdr(lua_State *L, int idx, struct ip6_hdr *ip6
|
||||
lua_getfield(L,-1, "data");
|
||||
if (lua_type(L,-1)!=LUA_TSTRING) goto err;
|
||||
if (!(p=(uint8_t*)lua_tolstring(L,-1,&l))) l=0;
|
||||
if (l<6 || (l+2)>left || (type==IPPROTO_AH ? (l>=1024 || ((l+2) & 3)) : (l>=2048 || ((l+2) & 7)))) goto err;
|
||||
memcpy(data+2,p,l);
|
||||
l+=2;
|
||||
|
||||
if (l<6 || (l+2)>left) goto err;
|
||||
if (type==IPPROTO_AH)
|
||||
{
|
||||
if (l>=1024 || ((l+2) & 3)) goto err;
|
||||
memcpy(data+2,p,l);
|
||||
l+=2;
|
||||
data[1] = (l>>2)-2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (l>=2048 || ((l+2) & 7)) goto err;
|
||||
memcpy(data+2,p,l);
|
||||
l+=2;
|
||||
data[1] = (l>>3)-1;
|
||||
}
|
||||
|
||||
data[0] = next; // may be overwritten later
|
||||
data[1] = (type==IPPROTO_AH) ? (l>>2)-2 : (l>>3)-1;
|
||||
if (!preserve_next) *last_proto = type;
|
||||
last_proto = data; // first byte of header holds type
|
||||
left -= l; data += l; filled += l;
|
||||
@@ -2018,7 +2031,7 @@ bool lua_reconstruct_iphdr(lua_State *L, int idx, struct ip *ip, size_t *len)
|
||||
|
||||
LUA_STACK_GUARD_ENTER(L)
|
||||
|
||||
if (*len<sizeof(struct ip) || lua_type(L,-1)!=LUA_TTABLE) return false;
|
||||
if (*len<sizeof(struct ip) || lua_type(L,idx)!=LUA_TTABLE) return false;
|
||||
|
||||
ip->ip_v = IPVERSION;
|
||||
|
||||
@@ -2188,7 +2201,7 @@ err:
|
||||
}
|
||||
bool lua_reconstruct_tcphdr(lua_State *L, int idx, struct tcphdr *tcp, size_t *len)
|
||||
{
|
||||
if (*len<sizeof(struct tcphdr) || lua_type(L,-1)!=LUA_TTABLE) return false;
|
||||
if (*len<sizeof(struct tcphdr) || lua_type(L,idx)!=LUA_TTABLE) return false;
|
||||
|
||||
LUA_STACK_GUARD_ENTER(L)
|
||||
|
||||
@@ -2263,7 +2276,7 @@ static int luacall_reconstruct_tcphdr(lua_State *L)
|
||||
|
||||
bool lua_reconstruct_udphdr(lua_State *L, int idx, struct udphdr *udp)
|
||||
{
|
||||
if (lua_type(L,-1)!=LUA_TTABLE) return false;
|
||||
if (lua_type(L,idx)!=LUA_TTABLE) return false;
|
||||
|
||||
LUA_STACK_GUARD_ENTER(L)
|
||||
|
||||
@@ -2307,7 +2320,7 @@ static int luacall_reconstruct_udphdr(lua_State *L)
|
||||
|
||||
bool lua_reconstruct_icmphdr(lua_State *L, int idx, struct icmp46 *icmp)
|
||||
{
|
||||
if (lua_type(L,-1)!=LUA_TTABLE) return false;
|
||||
if (lua_type(L,idx)!=LUA_TTABLE) return false;
|
||||
|
||||
LUA_STACK_GUARD_ENTER(L)
|
||||
|
||||
@@ -3714,7 +3727,7 @@ static void lua_xtime(lua_State *L, struct tm *(*timefunc)(const time_t *,struct
|
||||
lua_pushf_int(L,"isdst", t.tm_isdst);
|
||||
lua_pushf_str(L,"zone", t.tm_zone);
|
||||
|
||||
char s[24];
|
||||
char s[40];
|
||||
snprintf(s,sizeof(s),"%02d.%02d.%04d %02d:%02d:%02d", t.tm_mday, t.tm_mon + 1, t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec);
|
||||
lua_pushf_str(L,"str", s);
|
||||
}
|
||||
|
||||
37
nfq2/nfqws.c
37
nfq2/nfqws.c
@@ -260,8 +260,8 @@ static int nfq_cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_da
|
||||
uint32_t mark;
|
||||
struct ifreq ifr_in, ifr_out;
|
||||
|
||||
ph = nfq_get_msg_packet_hdr(nfa);
|
||||
id = ph ? ntohl(ph->packet_id) : 0;
|
||||
if (!(ph = nfq_get_msg_packet_hdr(nfa))) return 0; // should not happen
|
||||
id = ntohl(ph->packet_id);
|
||||
|
||||
mark = nfq_get_nfmark(nfa);
|
||||
ilen = nfq_get_payload(nfa, &data);
|
||||
@@ -378,7 +378,11 @@ static bool nfq_init(struct nfq_handle **h, struct nfq_q_handle **qh, struct nfq
|
||||
// dot not fail. not supported in old linuxes <3.6
|
||||
}
|
||||
|
||||
nfnl_rcvbufsiz(nfq_nfnlh(*h), Q_RCVBUF);
|
||||
unsigned int rcvbuf = nfnl_rcvbufsiz(nfq_nfnlh(*h), Q_RCVBUF) / 2;
|
||||
if (rcvbuf==Q_RCVBUF)
|
||||
DLOG("set receive buffer size to %u\n", rcvbuf);
|
||||
else
|
||||
DLOG_CONDUP("could not set receive buffer size to %u. real size is %u\n", Q_RCVBUF, rcvbuf);
|
||||
|
||||
int yes = 1, fd = nfq_fd(*h);
|
||||
|
||||
@@ -412,7 +416,7 @@ static int nfq_main(void)
|
||||
ssize_t rd;
|
||||
FILE *Fpid = NULL;
|
||||
uint8_t *buf=NULL, *mod=NULL;
|
||||
struct nfq_cb_data cbdata = { .sock = -1 };
|
||||
struct nfq_cb_data cbdata = { .sock = -1, .mod = NULL };
|
||||
|
||||
if (*params.pidfile && !(Fpid = fopen(params.pidfile, "w")))
|
||||
{
|
||||
@@ -517,11 +521,18 @@ static int nfq_main(void)
|
||||
// do not fail on ENOBUFS
|
||||
} while (e == ENOBUFS);
|
||||
|
||||
err:
|
||||
res=1;
|
||||
goto ex;
|
||||
|
||||
quit:
|
||||
DLOG_CONDUP("quit requested\n");
|
||||
exok:
|
||||
res=0;
|
||||
ex:
|
||||
free(cbdata.mod);
|
||||
if (Fpid) fclose(Fpid);
|
||||
if (cbdata.sock>=0) close(cbdata.sock);
|
||||
free(cbdata.mod);
|
||||
free(buf);
|
||||
nfq_deinit(&h, &qh);
|
||||
lua_shutdown();
|
||||
@@ -530,13 +541,6 @@ ex:
|
||||
#endif
|
||||
rawsend_cleanup();
|
||||
return res;
|
||||
err:
|
||||
if (Fpid) fclose(Fpid);
|
||||
res=1;
|
||||
goto ex;
|
||||
quit:
|
||||
DLOG_CONDUP("quit requested\n");
|
||||
goto exok;
|
||||
}
|
||||
|
||||
#elif defined(BSD)
|
||||
@@ -666,6 +670,7 @@ static int dvt_main(void)
|
||||
if (rd < 0)
|
||||
{
|
||||
DLOG_PERROR("recvfrom");
|
||||
if (errno==ENOBUFS) continue;
|
||||
goto exiterr;
|
||||
}
|
||||
else if (rd > 0)
|
||||
@@ -1280,7 +1285,7 @@ struct func_list *parse_lua_call(char *opt, struct func_list_head *flist)
|
||||
struct func_list *f = NULL;
|
||||
|
||||
if (!(name = item_name(&opt)))
|
||||
return false;
|
||||
return NULL;
|
||||
|
||||
if (!is_identifier(name) || !(f=funclist_add_tail(flist,name)))
|
||||
goto err;
|
||||
@@ -2533,7 +2538,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
break;
|
||||
case IDX_HOSTLIST_AUTO_FAIL_THRESHOLD:
|
||||
dp->hostlist_auto_fail_threshold = (uint8_t)atoi(optarg);
|
||||
dp->hostlist_auto_fail_threshold = atoi(optarg);
|
||||
if (dp->hostlist_auto_fail_threshold < 1 || dp->hostlist_auto_fail_threshold>20)
|
||||
{
|
||||
DLOG_ERR("auto hostlist fail threshold must be within 1..20\n");
|
||||
@@ -2542,7 +2547,7 @@ int main(int argc, char **argv)
|
||||
dp->b_hostlist_auto_fail_threshold = true;
|
||||
break;
|
||||
case IDX_HOSTLIST_AUTO_FAIL_TIME:
|
||||
dp->hostlist_auto_fail_time = (uint8_t)atoi(optarg);
|
||||
dp->hostlist_auto_fail_time = atoi(optarg);
|
||||
if (dp->hostlist_auto_fail_time < 1)
|
||||
{
|
||||
DLOG_ERR("auto hostlist fail time is not valid\n");
|
||||
@@ -2551,7 +2556,7 @@ int main(int argc, char **argv)
|
||||
dp->b_hostlist_auto_fail_time = true;
|
||||
break;
|
||||
case IDX_HOSTLIST_AUTO_RETRANS_THRESHOLD:
|
||||
dp->hostlist_auto_retrans_threshold = (uint8_t)atoi(optarg);
|
||||
dp->hostlist_auto_retrans_threshold = atoi(optarg);
|
||||
if (dp->hostlist_auto_retrans_threshold < 2 || dp->hostlist_auto_retrans_threshold>10)
|
||||
{
|
||||
DLOG_ERR("auto hostlist fail threshold must be within 2..10\n");
|
||||
|
||||
@@ -130,7 +130,7 @@ static int DLOG_FILENAME(const char *filename, const char *format, ...)
|
||||
}
|
||||
static void file_log_function(int priority, const char *line)
|
||||
{
|
||||
DLOG_FILENAME(params.debug_logfile,"%s",log_buf);
|
||||
DLOG_FILENAME(params.debug_logfile,"%s",line);
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
@@ -331,7 +331,7 @@ bool IsHttpReply(const uint8_t *data, size_t len)
|
||||
data[10]>='0' && data[10]<='9' &&
|
||||
data[11]>='0' && data[11]<='9';
|
||||
}
|
||||
int HttpReplyCode(const uint8_t *data, size_t len)
|
||||
int HttpReplyCode(const uint8_t *data)
|
||||
{
|
||||
return (data[9]-'0')*100 + (data[10]-'0')*10 + (data[11]-'0');
|
||||
}
|
||||
@@ -370,7 +370,7 @@ bool HttpReplyLooksLikeDPIRedirect(const uint8_t *data, size_t len, const char *
|
||||
|
||||
if (!host || !*host || !IsHttpReply(data, len)) return false;
|
||||
|
||||
code = HttpReplyCode(data,len);
|
||||
code = HttpReplyCode(data);
|
||||
|
||||
if ((code!=302 && code!=307) || !HttpExtractHeader(data,len,"\nLocation:",loc,sizeof(loc))) return false;
|
||||
|
||||
@@ -565,7 +565,7 @@ bool TLSFindExtLenOffsetInHandshake(const uint8_t *data, size_t len, size_t *off
|
||||
}
|
||||
bool TLSFindExtLen(const uint8_t *data, size_t len, size_t *off)
|
||||
{
|
||||
if (!TLSFindExtLenOffsetInHandshake(data+5,len-5,off))
|
||||
if (len<5 || !TLSFindExtLenOffsetInHandshake(data+5,len-5,off))
|
||||
return false;
|
||||
*off+=5;
|
||||
return true;
|
||||
@@ -1252,6 +1252,13 @@ static int cmp_range64(const void * a, const void * b)
|
||||
{
|
||||
return (((struct range64*)a)->offset < ((struct range64*)b)->offset) ? -1 : (((struct range64*)a)->offset > ((struct range64*)b)->offset) ? 1 : 0;
|
||||
}
|
||||
/*
|
||||
static bool intersected_u64(uint64_t l1, uint64_t r1, uint64_t l2, uint64_t r2)
|
||||
{
|
||||
return l1 <= r2 && l2 <= r1;
|
||||
}
|
||||
*/
|
||||
|
||||
bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,size_t *defrag_len, bool *bFull)
|
||||
{
|
||||
// Crypto frame can be split into multiple chunks
|
||||
@@ -1262,10 +1269,10 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
|
||||
uint8_t *defrag_data = defrag+10;
|
||||
size_t defrag_data_len = *defrag_len-10;
|
||||
uint8_t ft;
|
||||
uint64_t offset,sz,szmax=0,zeropos=0,pos=0;
|
||||
uint64_t offset,sz,szmax=0,zeropos=0,pos=0,r1,r2;
|
||||
bool found=false;
|
||||
struct range64 ranges[MAX_DEFRAG_PIECES];
|
||||
int i,range=0;
|
||||
int i,j,range=0;
|
||||
|
||||
while(pos<clean_len)
|
||||
{
|
||||
@@ -1292,12 +1299,18 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
|
||||
memset(defrag_data+zeropos,0,offset-zeropos);
|
||||
if ((offset+sz) > zeropos)
|
||||
zeropos=offset+sz;
|
||||
|
||||
memcpy(defrag_data+offset,clean+pos,sz);
|
||||
if ((offset+sz) > szmax) szmax = offset+sz;
|
||||
|
||||
found=true;
|
||||
pos+=sz;
|
||||
|
||||
// remove exact duplicates early to save cpu
|
||||
for(i=0;i<range;i++)
|
||||
if (ranges[i].offset==offset && ranges[i].len==sz)
|
||||
continue;
|
||||
|
||||
ranges[range].offset = offset;
|
||||
ranges[range].len = sz;
|
||||
range++;
|
||||
@@ -1305,6 +1318,30 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
qsort(ranges, range, sizeof(*ranges), cmp_range64);
|
||||
|
||||
// for(i=0 ; i<range ; i++)
|
||||
// printf("range1 %llu-%llu\n",ranges[i].offset,ranges[i].offset+ranges[i].len);
|
||||
|
||||
if (range>0)
|
||||
{
|
||||
for (j=0,i=1; i < range; i++)
|
||||
{
|
||||
uint64_t current_end = ranges[j].offset + ranges[j].len;
|
||||
uint64_t next_start = ranges[i].offset;
|
||||
uint64_t next_end = ranges[i].offset + ranges[i].len;
|
||||
|
||||
if (next_start <= current_end)
|
||||
ranges[j].len = MAX(next_end,current_end) - ranges[j].offset;
|
||||
else
|
||||
ranges[++j] = ranges[i];
|
||||
}
|
||||
range = j+1;
|
||||
}
|
||||
|
||||
// for(i=0 ; i<range ; i++)
|
||||
// printf("range2 %llu-%llu\n",ranges[i].offset,ranges[i].offset+ranges[i].len);
|
||||
|
||||
defrag[0] = 6;
|
||||
defrag[1] = 0; // offset
|
||||
// 2..9 - length 64 bit
|
||||
@@ -1313,21 +1350,7 @@ bool QUICDefragCrypto(const uint8_t *clean,size_t clean_len, uint8_t *defrag,siz
|
||||
defrag[2] |= 0xC0; // 64 bit value
|
||||
*defrag_len = (size_t)(szmax+10);
|
||||
|
||||
qsort(ranges, range, sizeof(*ranges), cmp_range64);
|
||||
|
||||
//for(i=0 ; i<range ; i++)
|
||||
// printf("RANGE %zu len %zu\n",ranges[i].offset,ranges[i].len);
|
||||
|
||||
for(i=0,offset=0,*bFull=true ; i<range ; i++)
|
||||
{
|
||||
if (ranges[i].offset!=offset)
|
||||
{
|
||||
*bFull = false;
|
||||
break;
|
||||
}
|
||||
offset += ranges[i].len;
|
||||
}
|
||||
|
||||
*bFull = range==1 && !ranges[0].offset;
|
||||
//printf("bFull=%u\n",*bFull);
|
||||
}
|
||||
return found;
|
||||
|
||||
@@ -104,7 +104,7 @@ bool HttpExtractHeader(const uint8_t *data, size_t len, const char *header, char
|
||||
bool HttpExtractHost(const uint8_t *data, size_t len, char *host, size_t len_host);
|
||||
bool IsHttpReply(const uint8_t *data, size_t len);
|
||||
// must be pre-checked by IsHttpReply
|
||||
int HttpReplyCode(const uint8_t *data, size_t len);
|
||||
int HttpReplyCode(const uint8_t *data);
|
||||
// must be pre-checked by IsHttpReply
|
||||
bool HttpReplyLooksLikeDPIRedirect(const uint8_t *data, size_t len, const char *host);
|
||||
|
||||
|
||||
@@ -95,6 +95,10 @@ bool dropcaps(void);
|
||||
|
||||
# define ARCH_NR AUDIT_ARCH_LOONGARCH64
|
||||
|
||||
#elif defined(__e2k__)
|
||||
|
||||
# define ARCH_NR AUDIT_ARCH_E2K
|
||||
|
||||
#else
|
||||
|
||||
# error "Platform does not support seccomp filter yet"
|
||||
|
||||
@@ -28,12 +28,6 @@ bool service_run(int argc, char *argv[])
|
||||
return StartServiceCtrlDispatcherA(ServiceTable);
|
||||
}
|
||||
|
||||
static void service_set_status(DWORD state)
|
||||
{
|
||||
ServiceStatus.dwCurrentState = state;
|
||||
SetServiceStatus(hStatus, &ServiceStatus);
|
||||
}
|
||||
|
||||
// Control handler function
|
||||
void service_controlhandler(DWORD request)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool service_run();
|
||||
bool service_run(int argc, char *argv[]);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user