mirror of
https://github.com/CHN-beta/xmurp-ua.git
synced 2026-01-11 01:09:25 +08:00
add useage
This commit is contained in:
14
Makefile
14
Makefile
@@ -1,8 +1,8 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=rkp-ua
|
||||
PKG_RELEASE:=33
|
||||
PKG_NAME:=xmurp-ua
|
||||
PKG_RELEASE:=99
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
@@ -14,12 +14,12 @@ EXTRA_CFLAGS:= \
|
||||
MAKE_OPTS:=$(KERNEL_MAKE_FLAGS) \
|
||||
SUBDIRS="$(PKG_BUILD_DIR)" \
|
||||
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
|
||||
CONFIG_RKP_UA=m
|
||||
CONFIG_XMURP_UA=m
|
||||
|
||||
define KernelPackage/rkp-ua
|
||||
define KernelPackage/xmurp-ua
|
||||
SUBMENU:=Other modules
|
||||
TITLE:=rkp-ua
|
||||
FILES:=$(PKG_BUILD_DIR)/rkp-ua.ko
|
||||
TITLE:=xmurp-ua
|
||||
FILES:=$(PKG_BUILD_DIR)/xmurp-ua.ko
|
||||
# AUTOLOAD:=$(call AutoLoad, 99, rkp-ua)
|
||||
KCONFIG:=
|
||||
endef
|
||||
@@ -28,4 +28,4 @@ define Build/Compile
|
||||
$(MAKE) -C "$(LINUX_DIR)" $(MAKE_OPTS) modules
|
||||
endef
|
||||
|
||||
$(eval $(call KernelPackage,rkp-ua))
|
||||
$(eval $(call KernelPackage,xmurp-ua))
|
||||
122
doc/compile.md
Normal file
122
doc/compile.md
Normal file
@@ -0,0 +1,122 @@
|
||||
以下,我假定你至少稍有一点命令行基础,搞不清当前目录或者 `cp`、`rm` 都不会用的话,自己找资料。
|
||||
|
||||
同时,以下内容中的代码仅仅是示例,目的是让你明白怎么回事,而不是复制粘贴就可以。
|
||||
|
||||
#### 一般的编译方法
|
||||
|
||||
对于 18.06 以上的 SDK,照这个方法就行了。
|
||||
|
||||
* 在电脑上安装一个 64 位的 Linux 系统。安装成虚拟机或双系统都可以。嫌麻烦的话,推荐使用 Win10 的 Ubuntu 子系统(WSL)。如果想要顺便体验实体机,强烈推荐 deepin。我使用的是 kubuntu 19.10。
|
||||
|
||||
* 安装编译依赖项。
|
||||
|
||||
```bash
|
||||
sudo apt-get update && sudo apt-get install git-core build-essential libssl-dev libncurses5-dev unzip gawk subversion mercurial ccache tar ssh
|
||||
```
|
||||
|
||||
记得开代理,或者换源。
|
||||
|
||||
* 准备 SDK。
|
||||
|
||||
必须使用与镜像完全对应的 SDK,而不能只是架构相同或者内核版本前三位相同。
|
||||
|
||||
官方 OpenWrt 的 SDK 和固件放在同一个目录下。比如,WNDR4300 的固件下载地址为:
|
||||
|
||||
```
|
||||
http://downloads.openwrt.org/releases/18.06.1/targets/ar71xx/nand/openwrt-18.06.1-ar71xx-nand-wndr4300-ubi-factory.img
|
||||
```
|
||||
|
||||
打开网站:
|
||||
|
||||
```
|
||||
http://downloads.openwrt.org/releases/18.06.1/targets/ar71xx/nand/
|
||||
```
|
||||
|
||||
就可以找到对应 SDK 的下载地址。
|
||||
|
||||
下载好 SDK 后,放到用户目录下,解压 SDK 并进入。
|
||||
|
||||
```bash
|
||||
cd ~ && tar xvf openwrt-sdk*.tar.xz && cd openwrt-sdk*
|
||||
```
|
||||
|
||||
(如果使用 WSL,可以将 SDK 放到 C 盘根目录,然后使用命令 `cd ~ && cp /mnt/c/*.tar.xz .` 将它复制到 WSL 中。)
|
||||
|
||||
* 下载 `xmurp-ua` 的源代码,并编译。
|
||||
|
||||
```bash
|
||||
git clone https://github.com/CHN-beta/xmurp-ua.git package/xmurp-ua
|
||||
make defconfig
|
||||
make package/xmurp-ua/compile V=sc
|
||||
```
|
||||
|
||||
编译好的包在 `bin` 中。
|
||||
|
||||
#### 增加编译参数
|
||||
|
||||
对于 18.06 以前的 SDK,编译的时候需要手动指定一些参数。参考[这篇文章](https://blog.csdn.net/wr132/article/details/78946200)。按照我的经验,一般来说,指定 `ARCH` 和 `CROSS-COMPILE` 就足够了。例如:
|
||||
|
||||
```bash
|
||||
make package/xmurp-ua/compile V=sc ARCH=mips CROSS_COMPILE=/home/chn/Desktop/lede-sdk-17.01.5-ar71xx-generic_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dir/toolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/bin/mips-openwrt-linux-musl-
|
||||
```
|
||||
|
||||
#### 使用旧版 Makefile
|
||||
|
||||
对于 Openwrt 15.05(Chaos Calmer),Makefile 的格式与最新版本不同。使用 `Chaos_Calmer.Makefile` 代替 `Makefile` 再编译。
|
||||
|
||||
```bash
|
||||
cp package/xmurp-ua/Chaos_Calmer.Makefile package/xmurp-ua/Makefile
|
||||
```
|
||||
|
||||
#### 失效的 host 命令
|
||||
|
||||
我还遇到过这样的情况:
|
||||
|
||||
```
|
||||
.find.bin: loadlocale.c:129: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
|
||||
.xargs.bin: loadlocale.c:129: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
|
||||
Aborted (core dumped)
|
||||
Aborted (core dumped)
|
||||
MODPOST 0 modules
|
||||
.find.bin: loadlocale.c:129: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
|
||||
.xargs.bin: loadlocale.c:129: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
|
||||
.sed.bin: loadlocale.c:129: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
|
||||
Aborted (core dumped)
|
||||
Aborted (core dumped)
|
||||
Aborted (core dumped)
|
||||
```
|
||||
|
||||
解决办法就是,用自己电脑上的来替换 SDK 里给的那些命令,然后重新编译。
|
||||
|
||||
```bash
|
||||
rm -r staging_dir/host/bin
|
||||
ln -s /usr/bin staging_dir/host/
|
||||
rm -r build_dir/target-mips_24kc_musl-1.1.16/linux-ar71xx_generic/xmurp-ua
|
||||
make package/xmurp-ua/compile V=sc ARCH=mips CROSS_COMPILE=/home/chn/Desktop/lede-sdk-17.01.5-ar71xx-generic_gcc-5.4.0_musl-1.1.16.Linux-x86_64/staging_dirtoolchain-mips_24kc_gcc-5.4.0_musl-1.1.16/bin/mips-openwrt-linux-musl-
|
||||
```
|
||||
|
||||
#### ARCH 混乱
|
||||
|
||||
在给某个潘多拉编译的时候,发现在一些地方 `ARCH` 为 `mips` 而另一些地方为 `mipsel`。记得之前给某个版本的 LEDE 编译时也出现过类似的错误。用软链接解决。
|
||||
|
||||
```bash
|
||||
cd build_dir
|
||||
ln -s target-mipsel_1004kc+dsp_uClibc-1.0.x target-mips_1004kc+dsp_uClibc-1.0.x
|
||||
cd ..
|
||||
make package/xmurp-ua/compile V=sc ARCH=mips CROSS_COMPILE=/home/chn/Desktop/PandoraBox-SDK-ralink-mt7621_gcc-5.5.0_uClibc-1.0.x.Linux-x86_64-2019-02-01-git-0231ad4b5/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-5.5.0_uClibc-1.0.x/bin/mipsel-openwrt-linux-
|
||||
```
|
||||
|
||||
#### objtool 缺失
|
||||
|
||||
今天在 deepin 上编译时,遇到了下面的问题:
|
||||
|
||||
```
|
||||
make[4]: *** No rule to make target 'tools/objtool/objtool', needed by '/home/chn/repo/xmurp-ua/debug/openwrt-sdk-18.06.5-x86-64_gcc-7.3.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/xmurp-ua/xmurp-ua.o'. Stop.
|
||||
```
|
||||
|
||||
解决办法是,把系统的 objtool 复制过来,然后再编译。
|
||||
|
||||
```bash
|
||||
mkdir ./build_dir/target-x86_64_musl/linux-x86_64/linux-4.14.151/tools/objtool
|
||||
cp /usr/src/linux-headers-4.15.0-30deepin-generic/tools/objtool/objtool ./build_dir/target-x86_64_musl/linux-x86_64/linux-4.14.151/tools/objtool/
|
||||
```
|
||||
74
doc/useage.md
Normal file
74
doc/useage.md
Normal file
@@ -0,0 +1,74 @@
|
||||
### 加载模块
|
||||
|
||||
因为还没有经过足够的测试,因此模块默认不启动,需要手动加载或者手动设置开机启动。
|
||||
|
||||
手动加载、卸载模块的方法是:
|
||||
|
||||
```bash
|
||||
# 加载模块,所有参数都使用默认值,重启后不会自动加载
|
||||
insmod xmurp-ua
|
||||
# 使用自定义参数加载模块,没有指定的参数仍然使用默认,支持的参数见下文
|
||||
insmod xmurp-ua 参数1=值1 参数2=值2
|
||||
# 卸载模块,不需要指定参数
|
||||
rmmod xmurp-ua
|
||||
```
|
||||
|
||||
设置开机启动的方法是,将下面的内容放到 `/etc/modules.d/99-xmurp-ua` 中:
|
||||
|
||||
```
|
||||
xmurp-ua 参数1=值1 参数2=值2
|
||||
```
|
||||
|
||||
同样,没有指定的参数会使用默认值。
|
||||
|
||||
### 支持的参数
|
||||
|
||||
默认的参数已经可以正常工作,只有需要设置例外或者调整什么的时候才需要自己指定参数。
|
||||
|
||||
* `str_preserve`:指定需要忽略的字符串,默认为空。推荐使用双引号套单引号的写法(可以兼容 ua 中带空格的问题),字符串之间用逗号隔开。例如:
|
||||
|
||||
```bash
|
||||
xmurp-ua str_preserve='"Windows NT,WeGame"'
|
||||
```
|
||||
|
||||
这样,所有包含“Windows NT”或“WeGame”的 ua 都会被放行。
|
||||
|
||||
* `autocapture`:是否自动根据端口号和 ip 判定是否捕获和如何处理,默认为 `y`(即”yes“)。可以设置成 `n`(即”no“),然后手动编写捕获规则,详细见下一条。
|
||||
|
||||
* `mark_capture` 和 `mark_ack`:用来配合防火墙自定义规则使用,让用户自己编写捕获的规则。只有当 `autocapture` 为 `n` 时,这两个参数才有意义。这两个参数的默认值分别为 `0x100`、`0x200`,它们的意义请看下面的示例:
|
||||
|
||||
```bash
|
||||
insmod xmurp-ua autocapture=n # 关闭自动捕获
|
||||
|
||||
iptables -t mangle -N ua_mod_req # 标记从客户端发到服务端的包
|
||||
iptables -t mangle -N ua_mod_ans # 标记从服务端发到客户端的包
|
||||
|
||||
# 需要在三个链中都放置规则
|
||||
iptables -t mangle -A INPUT -p tcp --sport 80 -j ua_mod_ans
|
||||
iptables -t mangle -A OUTPUT -p tcp --dport 80 -j ua_mod_req
|
||||
iptables -t mangle -A FORWARD -p tcp --sport 80 -j ua_mod_ans
|
||||
iptables -t mangle -A FORWARD -p tcp --dport 80 -j ua_mod_req
|
||||
|
||||
# 确认 ip 地址符合要求
|
||||
iptables -t mangle -A ua_mod_req ! -s 192.168.0.0/16 -j RETURN
|
||||
iptables -t mangle -A ua_mod_req -d 192.168.0.0/16 -j RETURN
|
||||
iptables -t mangle -A ua_mod_ans -s 192.168.0.0/16 -j RETURN
|
||||
iptables -t mangle -A ua_mod_ans ! -d 192.168.0.0/16 -j RETURN
|
||||
|
||||
# 打上需要的标记,这里假定 mark_capture 为 0x100,mark_ack 为 0x200
|
||||
# 从客户端到服务端的包需要全部打上 mark_capture,从客户端到服务端的带 ack 标志的包需要打上 mark_capture 和 mark_ack
|
||||
iptables -t mangle -A ua_mod_req -j MARK --set-xmark 0x100/0x100
|
||||
iptables -t mangle -A ua_mod_ans -p tcp --tcp-flags ack -j MARK --set-xmark 0x300/0x300
|
||||
```
|
||||
|
||||
上面的规则实现的效果与 `autocapture` 置为 `y` 时完全一致。
|
||||
|
||||
* `time_keepalive`:间隔多长时间检查一次监控的 tcp 流的活动情况,连续两次检查之间没有活动过的流就有可能被释放掉。单位为秒,默认值是 `1200`,意思是一个流超过 20 分钟不活动就可能被清理掉。例如:
|
||||
|
||||
```bash
|
||||
xmurp-ua time_keepalive=3600
|
||||
```
|
||||
|
||||
* `len_ua`:为了判断 ua 的情况,最多可以捕获多少个数据包,默认值为 `2`。这是为了兼容非 HTTP 协议的内容处理。按照一个数据包的应用层长度为 1000B 来估计,如果存在超过 1000 字节的 ua(一般是不会出现这样长的),就可能被认为不是 HTTP 协议而被放行。
|
||||
|
||||
* `verbose` 和 `debug`:在内核日志中打印更详细的信息,只是为了调试。默认值为 `n`。除非是软路由或者虚拟机,否则不要开,很容易卡死。
|
||||
@@ -1,2 +1,2 @@
|
||||
config RKP_UA
|
||||
tristate "rkp-ua"
|
||||
config XMURP_UA
|
||||
tristate "xmurp-ua"
|
||||
@@ -1 +1 @@
|
||||
obj-${CONFIG_RKP_UA} += rkp-ua.o
|
||||
obj-${CONFIG_XMURP_UA} += xmurp-ua.o
|
||||
@@ -399,9 +399,9 @@ unsigned rkpStream_execute(struct rkpStream* rkps, struct rkpPacket* rkpp)
|
||||
|
||||
int32_t __rkpStream_seq_desired(const struct rkpStream* rkps)
|
||||
{
|
||||
struct rkpPacket* rkpp = rkps -> buff_scan;
|
||||
if(debug)
|
||||
printk("rkpStream_seq_desired\n");
|
||||
struct rkpPacket* rkpp = rkps -> buff_scan;
|
||||
if(rkpp == 0)
|
||||
return 0;
|
||||
else
|
||||
|
||||
@@ -41,7 +41,7 @@ static int __init hook_init(void)
|
||||
{
|
||||
nfho[i].hook = hook_funcion;
|
||||
nfho[i].pf = NFPROTO_IPV4;
|
||||
nfho[i].priority = NF_IP_PRI_MANGLE;
|
||||
nfho[i].priority = NF_IP_PRI_MANGLE + 1;
|
||||
}
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
|
||||
ret = nf_register_net_hooks(&init_net, nfho, 3);
|
||||
@@ -51,11 +51,14 @@ static int __init hook_init(void)
|
||||
|
||||
printk("rkp-ua: Started, version %s\n", VERSION);
|
||||
printk("rkp-ua: nf_register_hook returnd %d.\n", ret);
|
||||
printk("rkp-ua: autocapture=%c, mark_capture=0x%x\n",
|
||||
'n' + autocapture * ('y' - 'n'), mark_capture);
|
||||
printk("rkp-ua: autocapture=%c, mark_capture=0x%x, mark_ack=0x%x\n",
|
||||
'n' + autocapture * ('y' - 'n'), mark_capture, mark_ack);
|
||||
printk("rkp-ua: str_preserve: %d\n", n_str_preserve);
|
||||
for(ret = 0; ret < n_str_preserve; ret++)
|
||||
printk("\t%s\n", str_preserve[ret]);
|
||||
printk("rkp-ua: time_keepalive=%d, len_ua=%d\n", time_keepalive, len_ua);
|
||||
printk("rkp-ua: verbose=%c, debug=%c\n", 'n' + verbose * ('y' - 'n'), 'n' + debug * ('y' - 'n'));
|
||||
printk("rkp-ua: str_preserve: %d\n", n_str_preserve);
|
||||
printk("str_ua_rkp: %s\n", str_uaRkp);
|
||||
|
||||
return 0;
|
||||
Reference in New Issue
Block a user