@@ -937,6 +937,82 @@ generate_slipnet_url() {
937937 echo " slipnet://$( echo -n " $data " | base64 -w0) "
938938}
939939
940+ # ─── microsocks GLIBC Fix ─────────────────────────────────────────────────────
941+
942+ compile_microsocks_from_source () {
943+ # The pre-built microsocks binary shipped by dnstm requires GLIBC ≥ 2.38.
944+ # Older distros (Ubuntu 22.04 = GLIBC 2.35, Debian 11 = 2.31) will fail to
945+ # run it. This function compiles microsocks from source as a fallback.
946+ print_info " Compiling microsocks from source (GLIBC compatibility fix)..."
947+
948+ # Ensure build tools are available
949+ if ! command -v gcc & > /dev/null || ! command -v make & > /dev/null; then
950+ print_info " Installing build tools (gcc, make, git)..."
951+ dpkg --configure -a 2> /dev/null || true
952+ apt-get update -qq 2> /dev/null || true
953+ apt-get install -y -qq build-essential git 2> /dev/null || true
954+ fi
955+
956+ if ! command -v gcc & > /dev/null; then
957+ print_fail " Cannot install gcc — microsocks will not work"
958+ return 1
959+ fi
960+
961+ local build_dir=" /tmp/microsocks-build-$$ "
962+ rm -rf " $build_dir "
963+
964+ if ! git clone --depth 1 https://github.com/rofl0r/microsocks.git " $build_dir " 2> /dev/null; then
965+ print_fail " Failed to clone microsocks source"
966+ rm -rf " $build_dir "
967+ return 1
968+ fi
969+
970+ if ! make -C " $build_dir " 2> /dev/null; then
971+ print_fail " Failed to compile microsocks"
972+ rm -rf " $build_dir "
973+ return 1
974+ fi
975+
976+ if [[ ! -f " $build_dir /microsocks" ]]; then
977+ print_fail " microsocks binary not produced"
978+ rm -rf " $build_dir "
979+ return 1
980+ fi
981+
982+ # Replace the broken binary
983+ systemctl stop microsocks 2> /dev/null || true
984+ cp " $build_dir /microsocks" /usr/local/bin/microsocks
985+ chmod +x /usr/local/bin/microsocks
986+ rm -rf " $build_dir "
987+
988+ # Restart service
989+ systemctl reset-failed microsocks 2> /dev/null || true
990+ systemctl daemon-reload 2> /dev/null || true
991+ if systemctl start microsocks 2> /dev/null; then
992+ sleep 2
993+ if pgrep -x microsocks & > /dev/null; then
994+ print_ok " microsocks compiled from source and running"
995+ return 0
996+ fi
997+ fi
998+
999+ print_fail " microsocks compiled but failed to start"
1000+ return 1
1001+ }
1002+
1003+ # Check whether the microsocks binary can actually execute on this system.
1004+ # Returns 0 if it works, 1 if GLIBC or another loader error is detected.
1005+ microsocks_binary_works () {
1006+ local bin=" ${1:-/ usr/ local/ bin/ microsocks} "
1007+ [[ -x " $bin " ]] || return 1
1008+ # Use ldd to check for missing shared library versions. GLIBC mismatches
1009+ # show "not found" in ldd output (e.g. "GLIBC_2.38 not found").
1010+ if ldd " $bin " 2>&1 | grep -qi " not found" ; then
1011+ return 1
1012+ fi
1013+ return 0
1014+ }
1015+
9401016# ─── Security Hardening Helpers ────────────────────────────────────────────────
9411017
9421018ensure_resolv_conf_fallback () {
@@ -2532,11 +2608,33 @@ step_verify_microsocks() {
25322608
25332609 systemctl enable microsocks 2> /dev/null || true
25342610 if systemctl start microsocks 2> /dev/null; then
2535- print_ok " microsocks started"
2536- microsocks_running=true
2611+ sleep 1
2612+ if pgrep -x microsocks & > /dev/null; then
2613+ print_ok " microsocks started"
2614+ microsocks_running=true
2615+ else
2616+ # May have crashed immediately — check for GLIBC issue
2617+ if ! microsocks_binary_works; then
2618+ print_warn " microsocks crashed (GLIBC incompatibility detected)"
2619+ if compile_microsocks_from_source; then
2620+ microsocks_running=true
2621+ fi
2622+ else
2623+ print_fail " Failed to start microsocks"
2624+ print_info " Check: systemctl status microsocks"
2625+ fi
2626+ fi
25372627 else
2538- print_fail " Failed to start microsocks"
2539- print_info " Check: systemctl status microsocks"
2628+ # systemctl start failed — check for GLIBC issue
2629+ if ! microsocks_binary_works; then
2630+ print_warn " microsocks binary incompatible — compiling from source..."
2631+ if compile_microsocks_from_source; then
2632+ microsocks_running=true
2633+ fi
2634+ else
2635+ print_fail " Failed to start microsocks"
2636+ print_info " Check: systemctl status microsocks"
2637+ fi
25402638 fi
25412639 fi
25422640
0 commit comments