37 Commits

Author SHA1 Message Date
Vadim Vetrov
da650bd09f Bump version 2025-12-28 12:56:11 +03:00
Vadim Vetrov
07334c598d Disable fake_sni parameter by default.
It seems like youtubeUnblock works even without --fake-sni
2025-12-27 17:46:25 +03:00
Vadim Vetrov
b35b6ed29c Update default SNI domain
Relates to #312
2025-11-22 16:24:42 +03:00
Vadim Vetrov
2d579d5479 Bump version
See branch openwrt
2025-08-15 08:39:28 +03:00
Vadim Vetrov
473af29c6b Bump version 2025-08-14 17:23:50 +03:00
Vadim Vetrov
5c809c893d Merge pull request #266 from Waujito/telegram-calls
Telegram Calls
2025-08-14 17:15:18 +03:00
Vadim Vetrov
ce859ed9f0 Note about --udp-stun-filter in README 2025-08-14 17:10:41 +03:00
Vadim Vetrov
23380f7b5c STUN: Filter request-only
On transit machines it was faking the traffic in two directions
2025-08-11 22:03:49 +03:00
Vadim Vetrov
65e3613a65 Add UDP STUN filter 2025-08-11 20:59:06 +03:00
Vadim Vetrov
d85c723bbe Do not do make in make install
Old behavior leads to permission errors on multiple rebuilds
2025-05-18 02:40:12 +03:00
Vadim Vetrov
71afca37e9 Mention kernel modules in troubleshooting
#247
2025-04-29 23:40:32 +03:00
Vadim Vetrov
6a138324d2 Mention kernel modules in troubleshooting
#247
2025-04-29 23:35:55 +03:00
Vadim Vetrov
6549d0075f Reoder config refcount acquire in kernel module
That's like an impossible occurrence but why not :)
2025-03-29 18:11:44 +03:00
Vadim Vetrov
9e8a2aab36 Update README.md 2025-03-21 03:45:16 +03:00
Vadim Vetrov
441c5f1fd2 Update README.md 2025-03-21 03:41:00 +03:00
Vadim Vetrov
8163213602 Add notice about kmod size 2025-02-23 01:55:40 +03:00
Vadim Vetrov
f37c3dd496 Bump version 2025-02-21 00:19:43 +03:00
Vadim Vetrov
0cf1035a14 Describe youtube does not work with all domains 2025-02-08 19:15:58 +03:00
Vadim Vetrov
7ebaccfa19 Merge branch 'aho_corasick' 2025-02-08 11:43:06 +03:00
Vadim Vetrov
705da0f4c6 Merge pull request #229 from metrapoliten/fixes
Различные фиксы
2025-02-07 18:23:48 +03:00
Vadim Vetrov
df70763b4a fix: safety defenders for delay_packet_send 2025-02-06 18:43:31 +03:00
Artyom Gavrilov
49304cc111 fix: добавление проверки malloc 2025-02-06 00:29:27 +03:00
Artyom Gavrilov
b832541766 fix: перемещение проверки на нужное место 2025-02-05 23:55:41 +03:00
Artyom Gavrilov
2884cb72f9 fix: проверка указателя перед разыменованием 2025-02-05 23:50:10 +03:00
Artyom Gavrilov
34271ece2c fix: восстановление проверки fseek
Вероятно в этом месте должна была быть проверка вызова fseek.
2025-02-05 23:50:10 +03:00
Artyom Gavrilov
ad6b84a961 fix: проверка ftell на возвращаемое значение 2025-02-05 23:50:10 +03:00
Artyom Gavrilov
5f20220d4e fix: изменение типа переменной на подходящий
По стандарту ftell возвращает long.
2025-02-05 23:50:10 +03:00
Artyom Gavrilov
6cc23a2991 fix: изменение проверки fseek
По стандарту fseek при неудаче возвращает любое значение кроме нуля.
2025-02-05 23:50:10 +03:00
Artyom Gavrilov
c73885aca3 fix: изменение проверки qversion
qversion >= 0, т.к. тип переменной - uint32_t. Провека должна быть по
переменной ret.
2025-02-05 23:48:46 +03:00
Artyom Gavrilov
78dd12c526 fix: проверка указателя до его использования 2025-02-05 22:52:13 +03:00
Artyom Gavrilov
d7489fc08a fix: проверка указателя до его использования 2025-02-05 22:47:02 +03:00
Vadim Vetrov
6da6f63541 Delete old domains data structures 2025-02-04 18:40:59 +03:00
Vadim Vetrov
a7b689b320 Fix warnings 2025-02-03 15:30:10 +03:00
Vadim Vetrov
f7d0bed7aa Use Aho-Corasick algorithm in tls parsing 2025-02-02 23:36:19 +03:00
Vadim Vetrov
d225e673c7 Implement Aho-Corasick algorithm 2025-02-02 20:00:57 +03:00
Vadim Vetrov
d9c360910b procfs for old kernels 2025-02-01 21:02:05 +03:00
Vadim Vetrov
42917a75fc Add youtubeUnblock statistics
The statistis will be printed on exit in userspace version. In kernel
space version, use `cat /proc/kyoutubeUnblock`.

The feature was proposed by @IceCat74 in #220
2025-02-01 20:38:33 +03:00
19 changed files with 746 additions and 191 deletions

2
Kbuild
View File

@@ -1,3 +1,3 @@
obj-m := kyoutubeUnblock.o obj-m := kyoutubeUnblock.o
kyoutubeUnblock-objs := src/kytunblock.o src/mangle.o src/quic.o src/quic_crypto.o src/utils.o src/tls.o src/getopt.o src/inet_ntop.o src/args.o deps/cyclone/aes.o deps/cyclone/cpu_endian.o deps/cyclone/ecb.o deps/cyclone/gcm.o deps/cyclone/hkdf.o deps/cyclone/hmac.o deps/cyclone/sha256.o kyoutubeUnblock-objs := src/kytunblock.o src/mangle.o src/quic.o src/quic_crypto.o src/utils.o src/tls.o src/getopt.o src/inet_ntop.o src/args.o src/trie.o deps/cyclone/aes.o deps/cyclone/cpu_endian.o deps/cyclone/ecb.o deps/cyclone/gcm.o deps/cyclone/hkdf.o deps/cyclone/hmac.o deps/cyclone/sha256.o
ccflags-y := -std=gnu99 -DKERNEL_SPACE -Wno-error -Wno-declaration-after-statement -I$(src)/src -I$(src)/deps/cyclone/include ccflags-y := -std=gnu99 -DKERNEL_SPACE -Wno-error -Wno-declaration-after-statement -I$(src)/src -I$(src)/deps/cyclone/include

View File

@@ -1,8 +1,8 @@
USPACE_TARGETS := default all install uninstall dev run_dev USPACE_TARGETS := default all install uninstall dev run_dev
KMAKE_TARGETS := kmake kload kunload kreload xmod xtclean KMAKE_TARGETS := kmake kload kunload kreload xmod xtclean
PKG_VERSION := 1.0.0 PKG_VERSION := 1.1.1
PKG_RELEASE := 6 PKG_RELEASE := 1
PKG_FULLVERSION := $(PKG_VERSION)-$(PKG_RELEASE) PKG_FULLVERSION := $(PKG_VERSION)-$(PKG_RELEASE)

View File

@@ -9,7 +9,7 @@
- [IPv6](#ipv6) - [IPv6](#ipv6)
- [Check it](#check-it) - [Check it](#check-it)
- [Flags](#flags) - [Flags](#flags)
- [UDP/QUIC/Voice Chats](#udpquicvoice-chats) - [UDP/QUIC](#udpquic)
- [Troubleshooting](#troubleshooting) - [Troubleshooting](#troubleshooting)
- [TV](#tv) - [TV](#tv)
- [Troubleshooting EPERMS (Operation not permitted)](#troubleshooting-eperms-operation-not-permitted) - [Troubleshooting EPERMS (Operation not permitted)](#troubleshooting-eperms-operation-not-permitted)
@@ -29,10 +29,22 @@
# youtubeUnblock # youtubeUnblock
Bypasses Deep Packet Inspection (DPI) systems that relies on SNI. The package is for Linux only. It is also fully compatible with routers running [OpenWRT](https://github.com/openwrt). Bypasses YouTube detection systems that rely on SNI.
The program was primarily developed to bypass YouTube Outage in Russia. The program was primarily developed to bypass YouTube Outage in Russia.
The program should be used **only for the YouTube platform**. It is legal since access to YouTube **is not officially restricted in Russia**. You **MUST NOT** use the program for any other purpose. I respect all Russian laws and do not wish to break any.
Starting with a YouTube speedup for my laptop, this project grew into a standalone tool that unblocks YouTube on a wide variety of devices. This project has fulfilled my dream of creating a massive, highly reliable, open-source GitHub project that helps people. I value all your feedback, and that is the reason I continue to maintain it. I learned many things while developing it, such as aspects of the Linux kernel networking stack. It is truly rewarding to explore new technologies while developing a project for people. This experience is incomparable to that of working on a mere pet project.
**So, please use it only for YouTube and only in accordance with the laws of your country.**
If you have any questions, suggestions, or problems, feel free to open an [issue](https://github.com/Waujito/youtubeUnblock/issues).
You are also welcome to contact me directly using the links provided in my GitHub profile description; however, please contact me only if you have a special offer. For help with the program, it is preferable to make our conversation public by posting on [GitHub Discussions](https://github.com/Waujito/youtubeUnblock/discussions).
The program is distributed under the GNU GPL v3 open-source license.
``` ```
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -44,6 +56,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
``` ```
The program is for Linux only. It is also fully compatible with routers running [OpenWRT](https://github.com/openwrt).
The program is distributed in two version: The program is distributed in two version:
- A userspace application works on top of nfnetlink queue which requires nfnetlink modules in the kernel and firewall rules. This approach is default and normally should be used but it has some limitations on embedded devices which may have no nfnetlink support. Also this solution may break down the internet speed and CPU load on your device because of jumps between userspace and kernelspace for each packet (this behavior may be fixed with connbytes but it also requires conntrack kernel module). - A userspace application works on top of nfnetlink queue which requires nfnetlink modules in the kernel and firewall rules. This approach is default and normally should be used but it has some limitations on embedded devices which may have no nfnetlink support. Also this solution may break down the internet speed and CPU load on your device because of jumps between userspace and kernelspace for each packet (this behavior may be fixed with connbytes but it also requires conntrack kernel module).
- A kernel module which integrates deeply within the netfilter stack and does not interact with the userspace firewall. The module requires only netfilter kernel support but it definetly present on every device connected to the Internet. The only difficulity is how to build it. I cannot provide modules within Github Actions for each single one kernel, even if we talk only about OpenWRT versions. If you want to learn more about the module, jump on [its section in the README](#kernel-module). Whats the benefits of the kernel module? The benefits come for some specific cases: the kernel module is the fastest thing that allows us to process every single packet sent to the linux network stack, while the normal youtubeUnblock requires connbytes to keep the internet speed. Speaking about connbytes, it also requires conntrack to operate, which may be a limitation on some transit-traffic machines. Also userspace youtubeUnblock requires modules for netlink queue, userspace firewall application and modules for it. The kernel module is much simpler and requires only the linux kernel with netfilter built in. - A kernel module which integrates deeply within the netfilter stack and does not interact with the userspace firewall. The module requires only netfilter kernel support but it definetly present on every device connected to the Internet. The only difficulity is how to build it. I cannot provide modules within Github Actions for each single one kernel, even if we talk only about OpenWRT versions. If you want to learn more about the module, jump on [its section in the README](#kernel-module). Whats the benefits of the kernel module? The benefits come for some specific cases: the kernel module is the fastest thing that allows us to process every single packet sent to the linux network stack, while the normal youtubeUnblock requires connbytes to keep the internet speed. Speaking about connbytes, it also requires conntrack to operate, which may be a limitation on some transit-traffic machines. Also userspace youtubeUnblock requires modules for netlink queue, userspace firewall application and modules for it. The kernel module is much simpler and requires only the linux kernel with netfilter built in.
@@ -52,8 +66,6 @@ The program is compatible with routers based on OpenWRT, Entware(Keenetic/ASUS)
On both OpenWRT and Entware install the program with opkg. If you got read-only filesystem error you may unpack the binary manually or specify opkg path `opkg -o <destdir>`. On both OpenWRT and Entware install the program with opkg. If you got read-only filesystem error you may unpack the binary manually or specify opkg path `opkg -o <destdir>`.
For Windows use [GoodbyeDPI by ValdikSS](https://github.com/ValdikSS/GoodbyeDPI) (you can find how to use it for YouTube [here](https://github.com/ValdikSS/GoodbyeDPI/issues/378)) The same behavior is also implemented in [zapret package for linux](https://github.com/bol-van/zapret).
## Configuration ## Configuration
### OpenWRT pre configuration ### OpenWRT pre configuration
@@ -281,19 +293,21 @@ Flags that do not scoped to a specific section, used over all the youtubeUnblock
- `--udp-fake-len=<size of udp fake>` Size of udp fake payload (typically payload is zeroes). Defaults to 64. - `--udp-fake-len=<size of udp fake>` Size of udp fake payload (typically payload is zeroes). Defaults to 64.
- `--udp-dport-filter=<5,6,200-500>` Filter the UDP destination ports. Defaults to no ports. Specifie the ports you want to be handled by youtubeUnblock. - `--udp-dport-filter=<5,6,200-500>` Filter the UDP destination ports. Defaults to no ports. Specifie the ports you want to be handled by youtubeUnblock. Please note, it may conflict with `--quic-drop` since `--quic-drop` setts `--udp-mode` to drop globally. So, make sure to handle it in a different config section.
- `--udp-stun-filter` Filter all the UDP STUN request packets. Very useful for voice chats. Please note, it may conflict with `--quic-drop` since `--quic-drop` setts `--udp-mode` to drop globally. So, make sure to handle it in a different config section.
- `--udp-faking-strategy={checksum|ttl|none}` Faking strategy for udp. `checksum` will fake UDP checksum, `ttl` won't fake but will make UDP content relatively small, `none` is no faking. Defaults to none. - `--udp-faking-strategy={checksum|ttl|none}` Faking strategy for udp. `checksum` will fake UDP checksum, `ttl` won't fake but will make UDP content relatively small, `none` is no faking. Defaults to none.
- `--udp-filter-quic={disabled|all|parse}` Enables QUIC filtering for UDP handler. If disabled, quic won't be processed, if all, all quic initial packets will be handled. `parse` will decrypt and parse QUIC initial message and match it with `--sni-domains`. Defaults to disabled. - `--udp-filter-quic={disabled|all|parse}` Enables QUIC filtering for UDP handler. If disabled, quic won't be processed, if all, all quic initial packets will be handled. `parse` will decrypt and parse QUIC initial message and match it with `--sni-domains`. Defaults to disabled.
- `--quic-drop` Drop all QUIC packets which goes to youtubeUnblock. Won't affect any other UDP packets. Just an alias for `--udp-filter-quic=all --udp-mode=drop`. - `--quic-drop` Drop all QUIC packets which goes to youtubeUnblock. Won't affect any other UDP packets. Just an alias for `--udp-filter-quic=all --udp-mode=drop`. Please note, because of `--udp-mode=drop` it may conflict with other filter options. Make sure to use multiple sections.
- `--no-dport-filter` By default, youtubeUnblock will filter for TLS and QUIC 443. If you want to disable it, pass this flag. (this does not affect `--udp-dport-filter`) - `--no-dport-filter` By default, youtubeUnblock will filter for TLS and QUIC 443. If you want to disable it, pass this flag. (this does not affect `--udp-dport-filter`)
## UDP/QUIC/Voice Chats ## UDP/QUIC
UDP is another communication protocol. Well-known technologies that use it are DNS, QUIC, voice chats. UDP does not provide reliable connection and its header is much simpler than TCP thus fragmentation is limited. The support provided primarily by faking. UDP is another communication protocol. Well-known technologies that use it are DNS, QUIC. UDP does not provide reliable connection and its header is much simpler than TCP thus fragmentation is limited. The support provided primarily by faking.
**For UDP faking in kernel module** Make sure to decrease `--connbytes-limit` up to 5. This will allow not to process additional packets and prevent network flood. **For UDP faking in kernel module** Make sure to decrease `--connbytes-limit` up to 5. This will allow not to process additional packets and prevent network flood.
@@ -303,7 +317,7 @@ QUIC is enabled with `--udp-filter-quic` flag. The flag supports two modes: `all
**I recommend to use** `--udp-mode=drop --udp-filter-quic=parse`. **I recommend to use** `--udp-mode=drop --udp-filter-quic=parse`.
For **other UDP protocols** I recommend to configure UDP support in the separate section from TCP, like `--fbegin --udp-dport-filter=50000-50099 --tls=disabled`. See more in flags related to udp and [tickets tagged with udp label](https://github.com/Waujito/youtubeUnblock/issues?q=label%3Audp+). For **other UDP protocols** I recommend to configure UDP support in the separate section from TCP, like `--fbegin --udp-dport-filter=50000-50099 --tls=disabled`. **You should not pass `--quic-drop` here unless you are sure what you are doing**
## Troubleshooting ## Troubleshooting
@@ -320,6 +334,10 @@ If your browser is using QUIC it may not work properly. Disable it in Chrome in
It seems like some TSPUs started to block wrongseq packets, so you should play around with faking strategies. I personally recommend to start with `md5sum` faking strategy. It seems like some TSPUs started to block wrongseq packets, so you should play around with faking strategies. I personally recommend to start with `md5sum` faking strategy.
#### youtube with `--sni-domains=all`
I know about this issue but it is **basically not an youtubeUnblock problem**. The problem is behind the large `*.googlevideo.com` domain name. All you want is to create a new configuration section for only youtube. It should go after section for all domains. For plain string arguments just `--fbegin` at the end of args list will work. In luci you can create section interactively.
### TV ### TV
Televisions are the biggest headache. Televisions are the biggest headache.
@@ -342,7 +360,7 @@ Where you have to replace 192.168.. with ip of your television.
*EPERM* may occur in a lot of places but generally here are two: *mnl_cb_run* and when sending the packet via *rawsocket* (raw_frags_send and send fake sni). *EPERM* may occur in a lot of places but generally here are two: *mnl_cb_run* and when sending the packet via *rawsocket* (raw_frags_send and send fake sni).
- **mnl_cb_run** *Operation not permitted* indicates that another instance of youtubeUnblock is running on the specified queue-num. - **mnl_cb_run** *Operation not permitted* indicates a problem in establishing a netfilter queue. This may occur due to various reasons, but the two most common are: issues with the nfqueue kernel modules and another instance of youtubeUnblock running with the same queue number. For the first issue, check that the kernel modules are installed and running. On OpenWRT, you might have forgotten to install the necessary dependencies [#openwrt-pre-configuration](#openwrt-pre-configuration). For the second issue, check for running youtubeUnblock instances by using the command `ps -e | grep youtubeUnblock`. If you find any, you can terminate them all with the command `killall youtubeUnblock`.
- **rawsocket** *Operation not permitted* indicates that the packet is being dropped by nefilter rules. In fact this is a hint from the kernel that something wrong is going on and we should check the firewall rules. Before dive into the problem let's make it clean how the mangled packets are being sent. Nefilter queue provides us with the ability to mangle the packet on fly but that is not suitable for this program because we need to split the packet to at least two independent packets. So we are using [linux raw sockets](https://man7.org/linux/man-pages/man7/raw.7.html) which allows us to send any ipv4 packet. **The packet goes from the OUTPUT chain even when NFQUEUE is set up on FORWARD (suitable for OpenWRT).** So we need to escape packet rejects here. - **rawsocket** *Operation not permitted* indicates that the packet is being dropped by nefilter rules. In fact this is a hint from the kernel that something wrong is going on and we should check the firewall rules. Before dive into the problem let's make it clean how the mangled packets are being sent. Nefilter queue provides us with the ability to mangle the packet on fly but that is not suitable for this program because we need to split the packet to at least two independent packets. So we are using [linux raw sockets](https://man7.org/linux/man-pages/man7/raw.7.html) which allows us to send any ipv4 packet. **The packet goes from the OUTPUT chain even when NFQUEUE is set up on FORWARD (suitable for OpenWRT).** So we need to escape packet rejects here.
* raw_frags_send EPERM: just make sure outgoing traffic is allowed (RELATED,ESTABLISHED should work, if not, go to step 3) * raw_frags_send EPERM: just make sure outgoing traffic is allowed (RELATED,ESTABLISHED should work, if not, go to step 3)
@@ -435,6 +453,12 @@ cat /sys/module/kyoutubeUnblock/parameters/parameters
and check all the parameters configured. and check all the parameters configured.
You can check up the statistics of youtubeUnblock with
```sh
sudo cat /proc/kyoutubeUnblock
```
### Building kernel module ### Building kernel module
#### Building on host system #### Building on host system
@@ -452,6 +476,12 @@ make kmake KERNEL_BUILDER_MAKEDIR=~/linux
``` ```
Note, that the kernel should be already configured and built. See linux kernel building manuals for more information about your specific case. Note, that the kernel should be already configured and built. See linux kernel building manuals for more information about your specific case.
**If you got a very large module, you can strip it and significiantly decrese the size:**
```sh
strip --strip-debug kyoutubeUnblock.ko
```
#### Building with openwrt SDK #### Building with openwrt SDK
Building with openwrt SDK is not such a hard thing. The only thing you should do is to obtain the sdk. You can find it by looking to your architecture and version of the openwrt currently used. You should use the exactly your version of openwrt since kernels there change often. You can find the sdk in two ways: by downloading it from their site or by using the openwrt sdk docker container (recommended). Building with openwrt SDK is not such a hard thing. The only thing you should do is to obtain the sdk. You can find it by looking to your architecture and version of the openwrt currently used. You should use the exactly your version of openwrt since kernels there change often. You can find the sdk in two ways: by downloading it from their site or by using the openwrt sdk docker container (recommended).
@@ -477,8 +507,3 @@ When the commands finish, the module is ready. Find it with `find bin -name "kmo
## Padavan ## Padavan
YoutubeUnblock may also run on Padavan. [Check the manual here\[rus\]](Padavan.md) YoutubeUnblock may also run on Padavan. [Check the manual here\[rus\]](Padavan.md)
>If you have any questions/suggestions/problems feel free to open an [issue](https://github.com/Waujito/youtubeUnblock/issues).

View File

@@ -157,7 +157,7 @@ typedef unsigned int uint_t;
#elif defined(__GNUC__) #elif defined(__GNUC__)
int strcasecmp(const char *s1, const char *s2); int strcasecmp(const char *s1, const char *s2);
int strncasecmp(const char *s1, const char *s2, size_t n); int strncasecmp(const char *s1, const char *s2, size_t n);
#if !(_SVID_SOURCE || _BSD_SOURCE || _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE) #if !(defined(_SVID_SOURCE) || defined(_BSD_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE))
char *strtok_r(char *s, const char *delim, char **last); char *strtok_r(char *s, const char *delim, char **last);
#endif #endif

View File

@@ -26,6 +26,7 @@
#include "getopt.h" #include "getopt.h"
#include "raw_replacements.h" #include "raw_replacements.h"
struct statistics_data global_stats;
/** /**
* Logging definitions * Logging definitions
@@ -61,14 +62,18 @@ static int read_file(const char* filename) {
} }
ret = fseek(fd, 0, SEEK_END); ret = fseek(fd, 0, SEEK_END);
if (ret < 0) { if (ret != 0) {
ret = -errno; ret = -errno;
goto close_file; goto close_file;
} }
size_t fsize = ftell(fd); long fsize = ftell(fd);
fseek(fd, 0, SEEK_SET); if (fsize == -1L) {
if (ret < 0) { ret = -errno;
goto close_file;
}
ret = fseek(fd, 0, SEEK_SET);
if (ret != 0) {
ret = -errno; ret = -errno;
goto close_file; goto close_file;
} }
@@ -93,10 +98,9 @@ close_file:
} }
#endif #endif
static int parse_sni_domains(struct domains_list **dlist, const char *domains_str, size_t domains_strlen) { static int parse_sni_domains(struct trie_container *trie, const char *domains_str, size_t domains_strlen) {
// Empty and shouldn't be used int ret;
struct domains_list ndomain = {0}; trie_init(trie);
struct domains_list *cdomain = &ndomain;
unsigned int j = 0; unsigned int j = 0;
for (unsigned int i = 0; i <= domains_strlen; i++) { for (unsigned int i = 0; i <= domains_strlen; i++) {
@@ -118,38 +122,22 @@ static int parse_sni_domains(struct domains_list **dlist, const char *domains_st
unsigned int domain_len = (i - j); unsigned int domain_len = (i - j);
const char *domain_startp = domains_str + j; const char *domain_startp = domains_str + j;
struct domains_list *edomain = malloc(sizeof(struct domains_list));
*edomain = (struct domains_list){0};
if (edomain == NULL) {
return -ENOMEM;
}
edomain->domain_len = domain_len; ret = trie_add_string(trie, (const uint8_t *)domain_startp, domain_len);
edomain->domain_name = malloc(domain_len + 1); if (ret < 0) {
if (edomain->domain_name == NULL) { lgerror(ret, "trie_add_string");
return -ENOMEM; return ret;
} }
strncpy(edomain->domain_name, domain_startp, domain_len);
edomain->domain_name[domain_len] = '\0';
cdomain->next = edomain;
cdomain = edomain;
j = i + 1; j = i + 1;
} }
} }
*dlist = ndomain.next;
return 0; return 0;
} }
static void free_sni_domains(struct domains_list *dlist) { static void free_sni_domains(struct trie_container *trie) {
for (struct domains_list *ldl = dlist; ldl != NULL;) { trie_destroy(trie);
struct domains_list *ndl = ldl->next;
SFREE(ldl->domain_name);
SFREE(ldl);
ldl = ndl;
}
} }
static long parse_numeric_option(const char* value) { static long parse_numeric_option(const char* value) {
@@ -284,6 +272,9 @@ static int parse_fake_custom_payload(
return -EINVAL; return -EINVAL;
} }
unsigned char *custom_buf = malloc(custom_len); unsigned char *custom_buf = malloc(custom_len);
if (custom_buf == NULL) {
return -ENOMEM;
}
for (int i = 0; i < custom_len; i++) { for (int i = 0; i < custom_len; i++) {
ret = sscanf(custom_hex_fake + (i << 1), "%2hhx", custom_buf + i); ret = sscanf(custom_hex_fake + (i << 1), "%2hhx", custom_buf + i);
@@ -342,6 +333,7 @@ enum {
OPT_UDP_FAKE_PAYLOAD_LEN, OPT_UDP_FAKE_PAYLOAD_LEN,
OPT_UDP_FAKING_STRATEGY, OPT_UDP_FAKING_STRATEGY,
OPT_UDP_DPORT_FILTER, OPT_UDP_DPORT_FILTER,
OPT_UDP_STUN_FILTER,
OPT_UDP_FILTER_QUIC, OPT_UDP_FILTER_QUIC,
OPT_TLS_ENABLED, OPT_TLS_ENABLED,
OPT_CLS, OPT_CLS,
@@ -382,6 +374,7 @@ static struct option long_opt[] = {
{"udp-fake-len", 1, 0, OPT_UDP_FAKE_PAYLOAD_LEN}, {"udp-fake-len", 1, 0, OPT_UDP_FAKE_PAYLOAD_LEN},
{"udp-faking-strategy", 1, 0, OPT_UDP_FAKING_STRATEGY}, {"udp-faking-strategy", 1, 0, OPT_UDP_FAKING_STRATEGY},
{"udp-dport-filter", 1, 0, OPT_UDP_DPORT_FILTER}, {"udp-dport-filter", 1, 0, OPT_UDP_DPORT_FILTER},
{"udp-stun-filter", 0, 0, OPT_UDP_STUN_FILTER},
{"udp-filter-quic", 1, 0, OPT_UDP_FILTER_QUIC}, {"udp-filter-quic", 1, 0, OPT_UDP_FILTER_QUIC},
{"no-dport-filter", 0, 0, OPT_NO_DPORT_FILTER}, {"no-dport-filter", 0, 0, OPT_NO_DPORT_FILTER},
{"threads", 1, 0, OPT_THREADS}, {"threads", 1, 0, OPT_THREADS},
@@ -449,6 +442,7 @@ void print_usage(const char *argv0) {
printf("\t--udp-fake-len=<size of upd fake>\n"); printf("\t--udp-fake-len=<size of upd fake>\n");
printf("\t--udp-faking-strategy={checksum|ttl|none}\n"); printf("\t--udp-faking-strategy={checksum|ttl|none}\n");
printf("\t--udp-dport-filter=<5,6,200-500>\n"); printf("\t--udp-dport-filter=<5,6,200-500>\n");
printf("\t--udp-stun-filter\n");
printf("\t--udp-filter-quic={disabled|all|parse}\n"); printf("\t--udp-filter-quic={disabled|all|parse}\n");
printf("\t--no-dport-filter\n"); printf("\t--no-dport-filter\n");
printf("\t--threads=<threads number>\n"); printf("\t--threads=<threads number>\n");
@@ -632,7 +626,7 @@ int yparse_args(struct config_t *config, int argc, char *argv[]) {
break; break;
case OPT_SNI_DOMAINS: case OPT_SNI_DOMAINS:
free_sni_domains(sect_config->sni_domains); free_sni_domains(&sect_config->sni_domains);
sect_config->all_domains = 0; sect_config->all_domains = 0;
if (!strcmp(optarg, "all")) { if (!strcmp(optarg, "all")) {
sect_config->all_domains = 1; sect_config->all_domains = 1;
@@ -648,7 +642,7 @@ int yparse_args(struct config_t *config, int argc, char *argv[]) {
goto error; goto error;
#else #else
{ {
free_sni_domains(sect_config->sni_domains); free_sni_domains(&sect_config->sni_domains);
ret = read_file(optarg); ret = read_file(optarg);
if (ret < 0) { if (ret < 0) {
goto error; goto error;
@@ -661,7 +655,7 @@ int yparse_args(struct config_t *config, int argc, char *argv[]) {
} }
#endif #endif
case OPT_EXCLUDE_DOMAINS: case OPT_EXCLUDE_DOMAINS:
free_sni_domains(sect_config->exclude_sni_domains); free_sni_domains(&sect_config->exclude_sni_domains);
ret = parse_sni_domains(&sect_config->exclude_sni_domains, optarg, strlen(optarg)); ret = parse_sni_domains(&sect_config->exclude_sni_domains, optarg, strlen(optarg));
if (ret < 0) if (ret < 0)
goto error; goto error;
@@ -673,7 +667,7 @@ int yparse_args(struct config_t *config, int argc, char *argv[]) {
goto error; goto error;
#else #else
{ {
free_sni_domains(sect_config->exclude_sni_domains); free_sni_domains(&sect_config->exclude_sni_domains);
ret = read_file(optarg); ret = read_file(optarg);
if (ret < 0) { if (ret < 0) {
goto error; goto error;
@@ -936,6 +930,9 @@ int yparse_args(struct config_t *config, int argc, char *argv[]) {
} }
break; break;
} }
case OPT_UDP_STUN_FILTER:
sect_config->udp_stun_filter = 1;
break;
case OPT_UDP_FILTER_QUIC: case OPT_UDP_FILTER_QUIC:
if (strcmp(optarg, "disabled") == 0) { if (strcmp(optarg, "disabled") == 0) {
sect_config->udp_filter_quic = UDP_FILTER_QUIC_DISABLED; sect_config->udp_filter_quic = UDP_FILTER_QUIC_DISABLED;
@@ -1060,6 +1057,8 @@ static size_t print_config_section(const struct section_config_t *section, char
} }
print_cnf_buf("--seg2delay=%d", section->seg2_delay); print_cnf_buf("--seg2delay=%d", section->seg2_delay);
} else {
print_cnf_buf("--fake-sni=0");
} }
} else { } else {
print_cnf_buf("--tls=disabled"); print_cnf_buf("--tls=disabled");
@@ -1067,20 +1066,11 @@ static size_t print_config_section(const struct section_config_t *section, char
if (section->all_domains) { if (section->all_domains) {
print_cnf_buf("--sni-domains=all"); print_cnf_buf("--sni-domains=all");
} else if (section->sni_domains != NULL) { } else if (section->sni_domains.vx != NULL) {
print_cnf_raw("--sni-domains="); print_cnf_buf("--sni-domains=<trie of %zu vertexes>", section->sni_domains.sz);
for (struct domains_list *sne = section->sni_domains; sne != NULL; sne = sne->next) {
print_cnf_raw("%s,", sne->domain_name);
} }
print_cnf_raw(" "); if (section->exclude_sni_domains.vx != NULL) {
} print_cnf_buf("--exclude-domains=<trie of %zu vertexes>", section->sni_domains.sz);
if (section->exclude_sni_domains != NULL) {
print_cnf_raw("--exclude-domains=");
for (struct domains_list *sne = section->exclude_sni_domains; sne != NULL; sne = sne->next) {
print_cnf_raw("%s,", sne->domain_name);
}
print_cnf_raw(" ");
} }
switch(section->sni_detection) { switch(section->sni_detection) {
@@ -1117,6 +1107,10 @@ static size_t print_config_section(const struct section_config_t *section, char
break; break;
} }
if (section->udp_stun_filter) {
print_cnf_buf("--udp-stun-filter");
}
if (section->udp_dport_range_len != 0) { if (section->udp_dport_range_len != 0) {
print_cnf_raw("--udp-dport-filter="); print_cnf_raw("--udp-dport-filter=");
@@ -1241,11 +1235,11 @@ int init_section_config(struct section_config_t **section, struct section_config
#else #else
def_section = malloc(sizeof(struct section_config_t)); def_section = malloc(sizeof(struct section_config_t));
#endif #endif
*def_section = (struct section_config_t)default_section_config;
def_section->prev = prev;
if (def_section == NULL) if (def_section == NULL)
return -ENOMEM; return -ENOMEM;
*def_section = (struct section_config_t)default_section_config;
def_section->prev = prev;
ret = parse_sni_domains(&def_section->sni_domains, default_snistr, sizeof(default_snistr)); ret = parse_sni_domains(&def_section->sni_domains, default_snistr, sizeof(default_snistr));
if (ret < 0) { if (ret < 0) {
@@ -1280,10 +1274,8 @@ void free_config_section(struct section_config_t *section) {
SFREE(section->udp_dport_range); SFREE(section->udp_dport_range);
} }
free_sni_domains(section->sni_domains); free_sni_domains(&section->sni_domains);
section->sni_domains = NULL; free_sni_domains(&section->exclude_sni_domains);
free_sni_domains(section->exclude_sni_domains);
section->exclude_sni_domains = NULL;
section->fake_custom_pkt_sz = 0; section->fake_custom_pkt_sz = 0;
SFREE(section->fake_custom_pkt); SFREE(section->fake_custom_pkt);

View File

@@ -25,6 +25,7 @@
#endif #endif
#include "types.h" #include "types.h"
#include "trie.h"
typedef int (*raw_send_t)(const unsigned char *data, size_t data_len); typedef int (*raw_send_t)(const unsigned char *data, size_t data_len);
/** /**
@@ -52,20 +53,13 @@ struct udp_dport_range {
uint16_t end; uint16_t end;
}; };
struct domains_list {
char *domain_name;
uint16_t domain_len;
struct domains_list *next;
};
struct section_config_t { struct section_config_t {
int id; int id;
struct section_config_t *next; struct section_config_t *next;
struct section_config_t *prev; struct section_config_t *prev;
struct domains_list *sni_domains; struct trie_container sni_domains;
struct domains_list *exclude_sni_domains; struct trie_container exclude_sni_domains;
unsigned int all_domains; unsigned int all_domains;
int tls_enabled; int tls_enabled;
@@ -113,6 +107,7 @@ struct section_config_t {
struct udp_dport_range *udp_dport_range; struct udp_dport_range *udp_dport_range;
int udp_dport_range_len; int udp_dport_range_len;
int udp_stun_filter;
int udp_filter_quic; int udp_filter_quic;
}; };
@@ -237,8 +232,8 @@ enum {
}; };
#define default_section_config { \ #define default_section_config { \
.sni_domains = NULL, \ .sni_domains = {0}, \
.exclude_sni_domains = NULL, \ .exclude_sni_domains = {0}, \
.all_domains = 0, \ .all_domains = 0, \
.tls_enabled = 1, \ .tls_enabled = 1, \
.frag_sni_reverse = 1, \ .frag_sni_reverse = 1, \
@@ -246,7 +241,7 @@ enum {
.fragmentation_strategy = FRAGMENTATION_STRATEGY, \ .fragmentation_strategy = FRAGMENTATION_STRATEGY, \
.faking_strategy = FAKING_STRATEGY, \ .faking_strategy = FAKING_STRATEGY, \
.faking_ttl = FAKE_TTL, \ .faking_ttl = FAKE_TTL, \
.fake_sni = 1, \ .fake_sni = 0, \
.fake_sni_seq_len = 1, \ .fake_sni_seq_len = 1, \
.fake_sni_type = FAKE_PAYLOAD_DEFAULT, \ .fake_sni_type = FAKE_PAYLOAD_DEFAULT, \
.fake_custom_pkt = NULL, \ .fake_custom_pkt = NULL, \
@@ -339,4 +334,13 @@ struct packet_data {
struct ytb_conntrack yct; struct ytb_conntrack yct;
}; };
struct statistics_data {
unsigned long all_packet_counter;
unsigned long packet_counter;
unsigned long target_counter;
unsigned long sent_counter;
};
extern struct statistics_data global_stats;
#endif /* YTB_CONFIG_H */ #endif /* YTB_CONFIG_H */

View File

@@ -30,6 +30,7 @@
#include <linux/net.h> #include <linux/net.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/proc_fs.h>
#include <linux/netfilter.h> #include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv4.h>
@@ -329,6 +330,8 @@ erret_lc:
return ret; return ret;
} }
++global_stats.sent_counter;
int ipvx = netproto_version(pkt, pktlen); int ipvx = netproto_version(pkt, pktlen);
if (ipvx == IP4VERSION) { if (ipvx == IP4VERSION) {
@@ -480,8 +483,10 @@ static NF_CALLBACK(ykb_nf_hook, skb) {
uint8_t *data_buf = NULL; uint8_t *data_buf = NULL;
int nf_verdict = NF_ACCEPT; int nf_verdict = NF_ACCEPT;
kref_get(&cur_config->refcount);
struct config_t *config = cur_config; struct config_t *config = cur_config;
kref_get(&config->refcount);
++global_stats.all_packet_counter;
if ((skb->mark & config->mark) == config->mark) { if ((skb->mark & config->mark) == config->mark) {
goto send_verdict; goto send_verdict;
@@ -523,12 +528,14 @@ static NF_CALLBACK(ykb_nf_hook, skb) {
pd.payload_len = skb->len; pd.payload_len = skb->len;
int vrd = process_packet(config, &pd); int vrd = process_packet(config, &pd);
++global_stats.packet_counter;
switch(vrd) { switch(vrd) {
case PKT_ACCEPT: case PKT_ACCEPT:
nf_verdict = NF_ACCEPT; nf_verdict = NF_ACCEPT;
break; break;
case PKT_DROP: case PKT_DROP:
++global_stats.target_counter;
nf_verdict = NF_STOLEN; nf_verdict = NF_STOLEN;
kfree_skb(skb); kfree_skb(skb);
break; break;
@@ -580,6 +587,37 @@ static struct pernet_operations ykb_pernet_ops = {
}; };
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) */ #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) */
#ifdef CONFIG_PROC_FS
static int proc_stats_show(struct seq_file *s, void *v) {
seq_printf(s, "youtubeUnblock stats: \n"
"\tCatched: %ld packets\n"
"\tProcessed: %ld packets\n"
"\tTargetted: %ld packets\n"
"\tSent over socket %ld packets\n",
global_stats.all_packet_counter, global_stats.packet_counter,
global_stats.target_counter, global_stats.sent_counter);
return 0;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,18,0)
static int proc_stats_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_stats_show, NULL);
}
static const struct file_operations proc_stats_operations = {
.open = proc_stats_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif /* KERNEL_VERSION */
#endif /* CONFIG_PROC_FS */
static int __init ykb_init(void) { static int __init ykb_init(void) {
int ret; int ret;
@@ -615,6 +653,18 @@ static int __init ykb_init(void) {
} }
#endif /* NO_IPV6 */ #endif /* NO_IPV6 */
#ifdef CONFIG_PROC_FS
if (!
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0)
proc_create_single("kyoutubeUnblock", 0, NULL, proc_stats_show)
#else
proc_create("kyoutubeUnblock", 0, NULL, &proc_stats_operations)
#endif
) {
lgwarning("kyoutubeUnblock procfs entry creation failed");
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
ret = register_pernet_subsys(&ykb_pernet_ops); ret = register_pernet_subsys(&ykb_pernet_ops);
#else #else
@@ -651,6 +701,10 @@ static void __exit ykb_destroy(void) {
close_raw6_socket(); close_raw6_socket();
#endif #endif
#ifdef CONFIG_PROC_FS
remove_proc_entry("kyoutubeUnblock", NULL);
#endif
close_raw_socket(); close_raw_socket();
kref_put(&cur_config->refcount, config_release); kref_put(&cur_config->refcount, config_release);
lginfo("youtubeUnblock kernel module destroyed.\n"); lginfo("youtubeUnblock kernel module destroyed.\n");

View File

@@ -345,6 +345,15 @@ int process_tcp_packet(const struct section_config_t *section, const uint8_t *ra
ipd_offset = target_sni_offset; ipd_offset = target_sni_offset;
mid_offset = ipd_offset + vrd.target_sni_len / 2; mid_offset = ipd_offset + vrd.target_sni_len / 2;
// hardcode googlevideo.com split
// googlevideo domains are very long, so
// it is possible for the entire domain to not be
// splitted (split goes for subdomain)
if (vrd.target_sni_len > 30) {
mid_offset = ipd_offset +
vrd.target_sni_len - 12;
}
size_t poses[2]; size_t poses[2];
int cnt = 0; int cnt = 0;
@@ -502,18 +511,11 @@ drop:
int send_ip4_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) { int send_ip4_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
if (poses_sz == 0) { if (poses_sz == 0) {
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) { if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
if (!instance_config.send_delayed_packet) { return instance_config.send_delayed_packet(
return -EINVAL;
}
lgtrace_addp("Sent %zu delayed for %d", pktlen, section->seg2_delay);
instance_config.send_delayed_packet(
packet, pktlen, section->seg2_delay); packet, pktlen, section->seg2_delay);
return 0;
} else { } else {
lgtrace_addp("Sent %zu bytes", pktlen);
return instance_config.send_raw_packet( return instance_config.send_raw_packet(
packet, pktlen); packet, pktlen);
} }
@@ -588,18 +590,11 @@ out:
int send_tcp_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) { int send_tcp_frags(const struct section_config_t *section, const uint8_t *packet, size_t pktlen, const size_t *poses, size_t poses_sz, size_t dvs) {
if (poses_sz == 0) { if (poses_sz == 0) {
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
if (!instance_config.send_delayed_packet) {
return -EINVAL;
}
instance_config.send_delayed_packet(
packet, pktlen, section->seg2_delay);
return 0;
} else {
lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs); lgtrace_addp("raw send packet of %zu bytes with %zu dvs", pktlen, dvs);
if (section->seg2_delay && ((dvs > 0) ^ section->frag_sni_reverse)) {
return instance_config.send_delayed_packet(
packet, pktlen, section->seg2_delay);
} else {
return instance_config.send_raw_packet( return instance_config.send_raw_packet(
packet, pktlen); packet, pktlen);
} }

View File

@@ -71,7 +71,7 @@ int quic_check_is_initial(const struct quic_lhdr *qch) {
uint32_t qversion; uint32_t qversion;
int ret; int ret;
ret = quic_get_version(&qversion, qch); ret = quic_get_version(&qversion, qch);
if (qversion < 0) return 0; if (ret < 0) return 0;
uint8_t qtype = qch->type; uint8_t qtype = qch->type;
@@ -426,6 +426,48 @@ out:
return 0; return 0;
} }
int is_stun_message(const uint8_t *data, size_t dlen) {
size_t left_len = dlen;
const uint8_t *data_ptr = data;
uint16_t message_type;
uint16_t message_length;
if (left_len < 2 + 2 + 4 + 12) {
return 0;
}
message_type = *(uint16_t *)data_ptr;
data_ptr += 2;
left_len -= 2;
message_length = *(uint16_t *)data_ptr;
data_ptr += 2;
left_len -= 2;
data_ptr += 4;
left_len -= 4;
data_ptr += 12;
left_len -= 12;
message_type = ntohs(message_type);
message_length = ntohs(message_length);
if (left_len != message_length) {
return 0;
}
if ((message_type & (1 << 15)) || (message_type & (1 << 14))) {
return 0;
}
// Filter request only
if ((message_type & (1 << 4)) || (message_type & (1 << 8))) {
return 0;
}
return 1;
}
int detect_udp_filtered(const struct section_config_t *section, int detect_udp_filtered(const struct section_config_t *section,
const uint8_t *payload, size_t plen) { const uint8_t *payload, size_t plen) {
const void *iph; const void *iph;
@@ -544,6 +586,11 @@ match_port:
} }
} }
if (section->udp_stun_filter && is_stun_message(data, dlen)) {
lgtrace_addp("STUN protocol detected");
goto approve;
}
skip: skip:
return 0; return 0;
approve: approve:

View File

@@ -82,6 +82,10 @@ int quic_parse_initial_message(
ret = quic_parse_data(quic_payload, quic_plen, ret = quic_parse_data(quic_payload, quic_plen,
&qch, &qch_len, &qci, &inpayload, &inplen &qch, &qch_len, &qci, &inpayload, &inplen
); );
if (ret < 0) {
lgerror(ret, "quic_parse_data");
goto error_nfr;
}
ret = quic_get_version(&qversion, qch); ret = quic_get_version(&qversion, qch);
if (ret < 0) { if (ret < 0) {
@@ -117,10 +121,6 @@ int quic_parse_initial_message(
} }
quic_header_len = inpayload - quic_payload; quic_header_len = inpayload - quic_payload;
if (ret < 0) {
lgerror(ret, "quic_parse_data");
goto error_nfr;
}
ret = quic_parse_initial_header(inpayload, inplen, &qich); ret = quic_parse_initial_header(inpayload, inplen, &qich);
if (ret < 0) { if (ret < 0) {

View File

@@ -33,6 +33,8 @@ int bruteforce_analyze_sni_str(
const uint8_t *data, size_t dlen, const uint8_t *data, size_t dlen,
struct tls_verdict *vrd struct tls_verdict *vrd
) { ) {
size_t offset, offlen;
int ret;
*vrd = (struct tls_verdict){0}; *vrd = (struct tls_verdict){0};
if (dlen <= 1) { if (dlen <= 1) {
@@ -47,50 +49,17 @@ int bruteforce_analyze_sni_str(
vrd->target_sni_len = vrd->sni_len; vrd->target_sni_len = vrd->sni_len;
return 0; return 0;
} }
int max_domain_len = 0;
for (struct domains_list *sne = section->sni_domains; sne != NULL; // It is safe for multithreading, so dp mutability is ok
sne = sne->next) { ret = trie_process_str((struct trie_container *)&section->sni_domains, data, dlen, 0, &offset, &offlen);
max_domain_len = max((int)sne->domain_len, max_domain_len); if (ret) {
}
size_t buf_size = max_domain_len + dlen + 1;
uint8_t *buf = malloc(buf_size);
if (buf == NULL) {
return -ENOMEM;
}
int *nzbuf = malloc(buf_size * sizeof(int));
if (nzbuf == NULL) {
free(buf);
return -ENOMEM;
}
for (struct domains_list *sne = section->sni_domains; sne != NULL; sne = sne->next) {
const char *domain_startp = sne->domain_name;
int domain_len = sne->domain_len;
int *zbuf = (void *)nzbuf;
memcpy(buf, domain_startp, domain_len);
memcpy(buf + domain_len, "#", 1);
memcpy(buf + domain_len + 1, data, dlen);
z_function((char *)buf, zbuf, domain_len + 1 + dlen);
for (size_t k = 0; k < domain_len + 1 + dlen; k++) {
if (zbuf[k] == domain_len) {
vrd->target_sni = 1; vrd->target_sni = 1;
vrd->sni_len = domain_len; vrd->sni_len = offlen;
vrd->sni_ptr = data + (k - domain_len - 1); vrd->sni_ptr = data + offset;
vrd->target_sni_ptr = vrd->sni_ptr; vrd->target_sni_ptr = vrd->sni_ptr;
vrd->target_sni_len = vrd->sni_len; vrd->target_sni_len = vrd->sni_len;
goto return_vrd;
} }
}
}
return_vrd:
free(buf);
free(nzbuf);
return 0; return 0;
} }
static int analyze_sni_str( static int analyze_sni_str(
@@ -98,44 +67,35 @@ static int analyze_sni_str(
const char *sni_name, int sni_len, const char *sni_name, int sni_len,
struct tls_verdict *vrd struct tls_verdict *vrd
) { ) {
int ret;
size_t offset, offlen;
if (section->all_domains) { if (section->all_domains) {
vrd->target_sni = 1; vrd->target_sni = 1;
goto check_domain; goto check_domain;
} }
for (struct domains_list *sne = section->sni_domains; sne != NULL; sne = sne->next) { // It is safe for multithreading, so dp mutability is ok
const char *sni_startp = sni_name + sni_len - sne->domain_len; ret = trie_process_str((struct trie_container *)&section->sni_domains,
const char *domain_startp = sne->domain_name; (const uint8_t *)sni_name, sni_len, TRIE_OPT_MAP_TO_END, &offset, &offlen);
if (ret) {
if (sni_len >= sne->domain_len &&
sni_len < 128 &&
!strncmp(sni_startp,
domain_startp,
sne->domain_len)) {
vrd->target_sni = 1; vrd->target_sni = 1;
vrd->target_sni_ptr = (const uint8_t *)sni_startp; vrd->target_sni_ptr = (const uint8_t *)sni_name + offset;
vrd->target_sni_len = sne->domain_len; vrd->target_sni_len = offlen;
break;
}
} }
check_domain: check_domain:
if (vrd->target_sni == 1) { if (vrd->target_sni == 1) {
for (struct domains_list *sne = section->exclude_sni_domains; sne != NULL; sne = sne->next) {
const char *sni_startp = sni_name + sni_len - sne->domain_len;
const char *domain_startp = sne->domain_name;
if (sni_len >= sne->domain_len && // It is safe for multithreading, so dp mutability is ok
sni_len < 128 && ret = trie_process_str((struct trie_container *)&section->exclude_sni_domains,
!strncmp(sni_startp, (const uint8_t *)sni_name, sni_len, TRIE_OPT_MAP_TO_END, &offset, &offlen);
domain_startp, if (ret) {
sne->domain_len)) {
vrd->target_sni = 0; vrd->target_sni = 0;
lgdebug("Excluded SNI: %.*s", lgdebug("Excluded SNI: %.*s",
vrd->sni_len, vrd->sni_ptr); vrd->sni_len, vrd->sni_ptr);
} }
} }
}
return 0; return 0;
} }

197
src/trie.c Normal file
View File

@@ -0,0 +1,197 @@
/*
youtubeUnblock - https://github.com/Waujito/youtubeUnblock
Copyright (C) 2024-2025 Vadim Vetrov <vetrovvd@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* This is slightly optimized Aho-Corasick implementation
*
* Big thanks to e-maxx http://e-maxx.ru/algo/aho_corasick
* for the best description and reference code samples
*/
#include "trie.h"
int trie_init(struct trie_container *trie) {
void *vx = malloc(sizeof(struct trie_vertex) * TRIE_STARTSZ);
if (vx == NULL) {
return -ENOMEM;
}
trie->vx = vx;
trie->arrsz = TRIE_STARTSZ;
trie->sz = 1;
struct trie_vertex *trx = trie->vx;
trx->p = trx->link = -1;
trx->leaf = 0;
trx->depth = 0;
trx->pch = 0;
memset(trx->go, 0xff, sizeof(trie->vx[0].go));
return 0;
}
void trie_destroy(struct trie_container *trie) {
trie->arrsz = 0;
trie->sz = 0;
free(trie->vx);
trie->vx = NULL;
}
/**
*
* Increases trie vertex container size.
* Returns new vertex index or ret < 0 on error
*
*/
static int trie_push_vertex(struct trie_container *trie) {
if (trie->sz == NMAX - 1) {
return -EINVAL;
}
if (trie->arrsz == trie->sz) { // realloc
void *pt = realloc(trie->vx,
sizeof(struct trie_vertex) * trie->arrsz * 2);
if (pt == NULL) {
return -ENOMEM;
}
trie->arrsz *= 2;
trie->vx = pt;
}
return trie->sz++;
}
int trie_add_string(struct trie_container *trie,
const uint8_t *str, size_t strlen) {
if (trie == NULL || trie->vx == NULL) {
return -EINVAL;
}
int v = 0;
int nv;
for (size_t i = 0; i < strlen; ++i) {
uint8_t c = str[i];
if (c >= TRIE_ALPHABET) {
return -EINVAL;
}
if (trie->vx[v].go[c] == -1) {
nv = trie_push_vertex(trie);
if (nv < 0) {
return nv;
}
struct trie_vertex *tvx = trie->vx + nv;
memset(tvx->go, 0xff, sizeof(tvx->go));
tvx->link = -1;
tvx->p = v;
tvx->depth = trie->vx[v].depth + 1;
tvx->leaf = 0;
tvx->pch = c;
trie->vx[v].go[c] = nv;
}
v = trie->vx[v].go[c];
}
if (v != 0) {
trie->vx[v].leaf = 1;
}
return 0;
}
static int trie_go(struct trie_container *trie,
int v, uint8_t c);
static int trie_get_link(struct trie_container *trie,
int v) {
struct trie_vertex *tvx = trie->vx + v;
if (tvx->link == -1) {
if (v == 0 || tvx->p == 0) {
tvx->link = 0;
} else {
tvx->link = trie_go(trie,
trie_get_link(trie, tvx->p), tvx->pch);
}
}
return tvx->link;
}
static int trie_go(struct trie_container *trie, int v, uint8_t c) {
struct trie_vertex *tvx = trie->vx + v;
if (tvx->go[c] == -1) {
tvx->go[c] = v == 0 ? 0 :
trie_go(trie, trie_get_link(trie, v), c);
}
return tvx->go[c];
}
int trie_process_str(
struct trie_container *trie,
const uint8_t *str, size_t strlen,
int flags,
size_t *offset, size_t *offlen
) {
if (trie == NULL || trie->vx == NULL) {
return 0;
}
int v = 0;
size_t i = 0;
uint8_t c;
int len;
for (; i < strlen; ++i) {
c = str[i];
if (c >= TRIE_ALPHABET) {
v = 0;
continue;
}
v = trie->vx[v].go[c] != -1 ? trie->vx[v].go[c] :
trie_go(trie, v, str[i]);
if (trie->vx[v].leaf &&
((flags & TRIE_OPT_MAP_TO_END) != TRIE_OPT_MAP_TO_END ||
i == strlen - 1)
) {
++i;
break;
}
}
len = trie->vx[v].depth;
if ( trie->vx[v].leaf &&
i >= len
) {
size_t sp = i - len;
*offset = sp;
*offlen = len;
return 1;
}
return 0;
}

92
src/trie.h Normal file
View File

@@ -0,0 +1,92 @@
/*
youtubeUnblock - https://github.com/Waujito/youtubeUnblock
Copyright (C) 2024-2025 Vadim Vetrov <vetrovvd@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* This is slightly optimized Aho-Corasick implementation
*
* Big thanks to e-maxx http://e-maxx.ru/algo/aho_corasick
* for the best description and reference code samples
*
*/
/**
*
* This algorithm allows us to search inside the string
* for a list of patterns in the linear time.
*
* The algorithm will lazily initialize itself while
* youtubeUnblock works. Lazy initializations considered
* safe for multithreading and operate without atomicity
* or synchronization primitives.
*
*/
#ifndef TRIE_H
#define TRIE_H
#include "types.h"
// ASCII alphabet
#define TRIE_ALPHABET 128
// Maximum of vertexes in the trie
#define NMAX ((1 << 15) - 1)
struct trie_vertex {
int leaf; // boolean flag
int depth; // depth of tree (length of substring)
int p; // parent
uint8_t pch; // vertex char
int link; // sufflink
int16_t go[TRIE_ALPHABET]; // dynamically filled pushes
};
struct trie_container {
struct trie_vertex *vx;
size_t arrsz;
size_t sz;
};
#define TRIE_STARTSZ 32
int trie_init(struct trie_container *trie);
void trie_destroy(struct trie_container *trie);
int trie_add_string(struct trie_container *trie,
const uint8_t *str, size_t strlen);
/**
* Aligns the pattern to the end
*/
#define TRIE_OPT_MAP_TO_END (1 << 1)
/**
* Searches the string for the patterns.
* flags is TRIE_OPT binary mask with options for search.
* offset, offlen are destination variables with
* offset of the given string and length of target.
*
* returns 1 if target found, 0 otherwise
*/
int trie_process_str(
struct trie_container *trie,
const uint8_t *str, size_t strlen,
int flags,
size_t *offset, size_t *offlen
);
#endif

View File

@@ -68,6 +68,7 @@ typedef __s16 int_least16_t; /* integer of >= 16 bits */
#define free kfree #define free kfree
#define malloc(size) kmalloc((size), GFP_KERNEL) #define malloc(size) kmalloc((size), GFP_KERNEL)
#define realloc(pt, size) krealloc((pt), (size), GFP_KERNEL)
#define calloc(n, size) kcalloc((n), (size), GFP_KERNEL) #define calloc(n, size) kcalloc((n), (size), GFP_KERNEL)
#define ip6_hdr ipv6hdr #define ip6_hdr ipv6hdr

View File

@@ -46,6 +46,7 @@
#include <linux/netfilter.h> #include <linux/netfilter.h>
#include <pthread.h> #include <pthread.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <signal.h>
#include "config.h" #include "config.h"
#include "mangle.h" #include "mangle.h"
@@ -546,6 +547,7 @@ erret_lc:
return ret; return ret;
} }
++global_stats.sent_counter;
int ipvx = netproto_version(pkt, pktlen); int ipvx = netproto_version(pkt, pktlen);
if (ipvx == IP4VERSION) { if (ipvx == IP4VERSION) {
@@ -612,14 +614,33 @@ void *delay_packet_send_fn(void *data) {
} }
int delay_packet_send(const unsigned char *data, size_t data_len, unsigned int delay_ms) { int delay_packet_send(const unsigned char *data, size_t data_len, unsigned int delay_ms) {
int ret;
struct dps_t *dpdt = malloc(sizeof(struct dps_t)); struct dps_t *dpdt = malloc(sizeof(struct dps_t));
if (dpdt == NULL) {
return -ENOMEM;
}
*dpdt = (struct dps_t){0};
dpdt->pkt = malloc(data_len); dpdt->pkt = malloc(data_len);
if (dpdt->pkt == NULL) {
free(dpdt);
return -ENOMEM;
}
memcpy(dpdt->pkt, data, data_len); memcpy(dpdt->pkt, data, data_len);
dpdt->pktlen = data_len; dpdt->pktlen = data_len;
dpdt->timer = delay_ms; dpdt->timer = delay_ms;
pthread_t thr; pthread_t thr = {0};
pthread_create(&thr, NULL, delay_packet_send_fn, dpdt); ret = pthread_create(&thr, NULL, delay_packet_send_fn, dpdt);
pthread_detach(thr); if (ret != 0) {
free(dpdt->pkt);
free(dpdt);
return -ret;
}
ret = pthread_detach(thr);
lgtrace_addp("Scheduled packet send after %d ms", delay_ms); lgtrace_addp("Scheduled packet send after %d ms", delay_ms);
return 0; return 0;
@@ -640,6 +661,8 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
uint16_t l3num; uint16_t l3num;
uint32_t id; uint32_t id;
++global_stats.all_packet_counter;
if (nfq_nlmsg_parse(nlh, attr) < 0) { if (nfq_nlmsg_parse(nlh, attr) < 0) {
lgerror(-errno, "Attr parse"); lgerror(-errno, "Attr parse");
return MNL_CB_ERROR; return MNL_CB_ERROR;
@@ -694,8 +717,11 @@ ct_out:
ret = process_packet(cur_config, &packet); ret = process_packet(cur_config, &packet);
++global_stats.packet_counter;
switch (ret) { switch (ret) {
case PKT_DROP: case PKT_DROP:
++global_stats.target_counter;
nfq_nlmsg_verdict_put(verdnlh, id, NF_DROP); nfq_nlmsg_verdict_put(verdnlh, id, NF_DROP);
break; break;
default: default:
@@ -875,6 +901,16 @@ struct instance_config_t instance_config = {
.send_delayed_packet = delay_packet_send, .send_delayed_packet = delay_packet_send,
}; };
void sigint_handler(int s) {
lginfo("youtubeUnblock stats: catched %ld packets, "
"processed %ld packets, "
"targetted %ld packets, sent over socket %ld packets",
global_stats.all_packet_counter, global_stats.packet_counter,
global_stats.target_counter, global_stats.sent_counter);
exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int ret; int ret;
struct config_t config; struct config_t config;
@@ -893,6 +929,8 @@ int main(int argc, char *argv[]) {
parse_global_lgconf(&config); parse_global_lgconf(&config);
cur_config = &config; cur_config = &config;
signal(SIGINT, sigint_handler);
signal(SIGTERM, sigint_handler);
if (open_raw_socket() < 0) { if (open_raw_socket() < 0) {
lgerror(-errno, "Unable to open raw socket"); lgerror(-errno, "Unable to open raw socket");

View File

@@ -10,6 +10,7 @@ static void RunAllTests(void)
{ {
RUN_TEST_GROUP(TLSTest) RUN_TEST_GROUP(TLSTest)
RUN_TEST_GROUP(QuicTest); RUN_TEST_GROUP(QuicTest);
RUN_TEST_GROUP(TrieTest);
} }
int main(int argc, const char * argv[]) int main(int argc, const char * argv[])

View File

@@ -36,22 +36,21 @@ TEST(TLSTest, Test_CHLO_message_detect)
TEST(TLSTest, Test_Bruteforce_detects) TEST(TLSTest, Test_Bruteforce_detects)
{ {
struct tls_verdict tlsv; struct tls_verdict tlsv;
struct domains_list dmns = { struct trie_container trie;
.domain_name = "youtube.com", int ret;
.domain_len = 11, ret = trie_init(&trie);
.next = NULL ret = trie_add_string(&trie, (uint8_t *)"youtube.com", 11);
}; sconf.sni_domains = trie;
sconf.sni_domains = &dmns;
int ret = bruteforce_analyze_sni_str(&sconf, (const uint8_t *)tls_bruteforce_message, sizeof(tls_bruteforce_message) - 1, &tlsv); ret = bruteforce_analyze_sni_str(&sconf, (const uint8_t *)tls_bruteforce_message, sizeof(tls_bruteforce_message) - 1, &tlsv);
TEST_ASSERT_EQUAL(0, ret); TEST_ASSERT_EQUAL(0, ret);
TEST_ASSERT_EQUAL(11, tlsv.sni_len); TEST_ASSERT_EQUAL(11, tlsv.sni_len);
TEST_ASSERT_EQUAL_STRING_LEN("youtube.com", tlsv.sni_ptr, 11); TEST_ASSERT_EQUAL_STRING_LEN("youtube.com", tlsv.sni_ptr, 11);
TEST_ASSERT_EQUAL_PTR(tls_bruteforce_message + TEST_ASSERT_EQUAL_PTR(tls_bruteforce_message +
sizeof(tls_bruteforce_message) - 12, tlsv.sni_ptr); sizeof(tls_bruteforce_message) - 12, tlsv.sni_ptr);
trie_destroy(&trie);
} }
TEST_GROUP_RUNNER(TLSTest) TEST_GROUP_RUNNER(TLSTest)
{ {
RUN_TEST_CASE(TLSTest, Test_CHLO_message_detect); RUN_TEST_CASE(TLSTest, Test_CHLO_message_detect);

147
test/trie.c Normal file
View File

@@ -0,0 +1,147 @@
#include "unity.h"
#include "unity_fixture.h"
#include "trie.h"
TEST_GROUP(TrieTest);
TEST_SETUP(TrieTest)
{
}
TEST_TEAR_DOWN(TrieTest)
{
}
const char ASTR[] = "abacaba";
const char BSTR[] = "BABABABA";
const char CSTR[] = "abracadabra";
const char tstr[] = "aBABABABDADAabacabracadabraabbbabacabaaaaaabacaba";
TEST(TrieTest, Trie_string_adds)
{
int ret;
size_t offset;
size_t offlen;
struct trie_container trie;
ret = trie_init(&trie);
TEST_ASSERT_EQUAL(0, ret);
ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1);
TEST_ASSERT_EQUAL(0, ret);
ret = trie_add_string(&trie, (uint8_t *)BSTR, sizeof(BSTR) - 1);
TEST_ASSERT_EQUAL(0, ret);
ret = trie_add_string(&trie, (uint8_t *)CSTR, sizeof(CSTR) - 1);
TEST_ASSERT_EQUAL(0, ret);
TEST_ASSERT_EQUAL(25, trie.sz);
trie_destroy(&trie);
}
TEST(TrieTest, Trie_string_finds)
{
int ret;
size_t offset;
size_t offlen;
struct trie_container trie;
ret = trie_init(&trie);
ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1);
ret = trie_add_string(&trie, (uint8_t *)BSTR, sizeof(BSTR) - 1);
ret = trie_add_string(&trie, (uint8_t *)CSTR, sizeof(CSTR) - 1);
ret = trie_process_str(&trie,
(uint8_t *)tstr, sizeof(tstr) - 1,
0, &offset, &offlen
);
TEST_ASSERT_EQUAL(1, ret);
TEST_ASSERT_EQUAL(11, offlen);
TEST_ASSERT_EQUAL_STRING_LEN("abracadabra", tstr + offset, offlen);
trie_destroy(&trie);
}
TEST(TrieTest, Trie_string_finds_opt_end)
{
int ret;
size_t offset;
size_t offlen;
struct trie_container trie;
ret = trie_init(&trie);
ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1);
ret = trie_add_string(&trie, (uint8_t *)BSTR, sizeof(BSTR) - 1);
ret = trie_add_string(&trie, (uint8_t *)CSTR, sizeof(CSTR) - 1);
ret = trie_process_str(&trie,
(uint8_t *)tstr, sizeof(tstr) - 1,
TRIE_OPT_MAP_TO_END,
&offset, &offlen
);
TEST_ASSERT_EQUAL(1, ret);
TEST_ASSERT_EQUAL(7, offlen);
TEST_ASSERT_EQUAL_STRING_LEN("abacaba", tstr + offset, offlen);
ret = trie_process_str(&trie,
(uint8_t *)tstr, sizeof(tstr),
TRIE_OPT_MAP_TO_END,
&offset, &offlen
);
TEST_ASSERT_EQUAL(0, ret);
trie_destroy(&trie);
}
TEST(TrieTest, Trie_single_vertex)
{
int ret;
size_t offset;
size_t offlen;
struct trie_container trie;
ret = trie_init(&trie);
ret = trie_process_str(&trie,
(uint8_t *)tstr, sizeof(tstr) - 1,
0,
&offset, &offlen
);
TEST_ASSERT_EQUAL(0, ret);
trie_destroy(&trie);
}
TEST(TrieTest, Trie_uninitialized)
{
int ret;
size_t offset;
size_t offlen;
struct trie_container trie = {0};
// ret = trie_init(&trie);
ret = trie_add_string(&trie, (uint8_t *)ASTR, sizeof(ASTR) - 1);
TEST_ASSERT_EQUAL(-EINVAL, ret);
ret = trie_process_str(&trie,
(uint8_t *)tstr, sizeof(tstr) - 1,
0,
&offset, &offlen
);
TEST_ASSERT_EQUAL(0, ret);
}
TEST_GROUP_RUNNER(TrieTest)
{
RUN_TEST_CASE(TrieTest, Trie_string_adds);
RUN_TEST_CASE(TrieTest, Trie_string_finds);
RUN_TEST_CASE(TrieTest, Trie_string_finds_opt_end);
RUN_TEST_CASE(TrieTest, Trie_single_vertex);
RUN_TEST_CASE(TrieTest, Trie_uninitialized);
}

View File

@@ -34,7 +34,7 @@ export CC CCLD LD CFLAGS LDFLAGS LIBNFNETLINK_CFLAGS LIBNFNETLINK_LIBS LIBMNL_CF
APP:=$(BUILD_DIR)/youtubeUnblock APP:=$(BUILD_DIR)/youtubeUnblock
TEST_APP:=$(BUILD_DIR)/testYoutubeUnblock TEST_APP:=$(BUILD_DIR)/testYoutubeUnblock
SRCS := mangle.c args.c utils.c quic.c tls.c getopt.c quic_crypto.c inet_ntop.c SRCS := mangle.c args.c utils.c quic.c tls.c getopt.c quic_crypto.c inet_ntop.c trie.c
OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o) OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
APP_EXEC := youtubeUnblock.c APP_EXEC := youtubeUnblock.c
APP_OBJ := $(APP_EXEC:%.c=$(BUILD_DIR)/%.o) APP_OBJ := $(APP_EXEC:%.c=$(BUILD_DIR)/%.o)
@@ -109,7 +109,10 @@ $(BUILD_DIR)/test/%.o: test/%.c $(REQ) $(INCLUDE_DIR)/config.h
@echo 'CC $@' @echo 'CC $@'
$(CC) -c $(CFLAGS) $(LDFLAGS) $(TEST_CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $(LDFLAGS) $(TEST_CFLAGS) $< -o $@
install: all install:
ifeq (,$(wildcard $(APP)))
$(error Make the binary first)
endif
install -d $(DESTDIR)$(PREFIX)/bin/ install -d $(DESTDIR)$(PREFIX)/bin/
install -m 755 $(APP) $(DESTDIR)$(PREFIX)/bin/ install -m 755 $(APP) $(DESTDIR)$(PREFIX)/bin/
install -d $(DESTDIR)$(PREFIX)/lib/systemd/system/ install -d $(DESTDIR)$(PREFIX)/lib/systemd/system/