gg.alert("此工具仅供学习(加密出来的shell文件只能防小白)") local Repeat = false--去重 local S_Str = true--神秘字符 local enc_random = true--打乱字符 local A_base = false--全局加载 local enc_Base = true--加密base64 local file_path = gg.getFile():gsub('[^/]*$', '') local config = gg.EXT_CACHE_DIR .. '/shell.cfg' local set = loadfile(config) if set then file_path = set()[1] end local function Table_Rand(t) local Upset_tab = {} local Dat_Total = #t while Dat_Total > 0 do local i = math.random(1,Dat_Total) table.insert(Upset_tab,t[i]) t[i] = t[Dat_Total] Dat_Total = Dat_Total -1 end return Upset_tab end function string.TurnSingle(Input_str) local GetCharSize = (function(char) if not char then return 0 elseif char > 240 then return 4 elseif char > 225 then return 3 elseif char > 192 then return 2 else return 1 end end) local Char = {} local i = 1 if not S_Str then while (i <= #Input_str) do local byte_Count = GetCharSize(curByte) Char[#Char + 1] = string.sub(Input_str, i, i + byte_Count - 1) i = i + byte_Count end else while (i <= #Input_str) do Char[#Char + 1] = string.sub(Input_str, i, i) i = i + 1 end end return Char end local function Shell_random(shell_pt) local function random_str(len)--随机 local res = {} for i = 1, len do local t = math.random(1, 2) if t == 1 then res[#res + 1] = string.char(math.random(65, 90)) else res[#res + 1] = string.char(math.random(97, 122)) end end return table.concat(res) end local Special_Characters = {--特殊符号 ['"'] = 2, ['$'] = 2, ['\\'] = 2, ['`'] = 2, } local t = {}--一个回调表 local _r = {} local r = {} local Char = string.TurnSingle(shell_pt) if Repeat then for i in ipairs(Char) do if not t[Char[i]] then local _S = random_str(3) t[Char[i]] = _S end end--获取 for i in ipairs(Char) do r[i] = t[Char[i]]--变量名替换 end for i in pairs(t) do if Special_Characters[i] then _r[#_r + 1] = t[i] .. "=\"\\" .. i .."\"" else _r[#_r + 1] = t[i] .. "=\"" .. i .. "\"" end end else for i in ipairs(Char) do local _S = random_str(5) r[i] = _S if Special_Characters[Char[i]] then _r[i] = _S .. "=\"\\" .. Char[i] .."\"" else _r[i] = _S .. "=\"" .. Char[i] .. "\"" end end--获取 end return table.concat(Table_Rand(_r), ";") .. "\n\n\neval \"$" .. table.concat(r, "$") .. "\"" end local function Base64_encrypt(s) local b64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" local rn = #s % 3 local st = {} local c1, c2, c3 local t4 = {} local lln, maxlln = 1, 72 for i = 1, #s, 3 do c1 = string.byte(s, i) c2 = string.byte(s, i+1) or 0 c3 = string.byte(s, i+2) or 0 t4[1] = string.char(string.byte(b64chars, (c1 >> 2) + 1)) t4[2] = string.char(string.byte(b64chars, (((c1 << 4)|(c2 >> 4)) & 0x3f) + 1)) t4[3] = string.char(string.byte(b64chars, (((c2 << 2)|(c3 >> 6)) & 0x3f) + 1)) t4[4] = string.char(string.byte(b64chars, (c3 & 0x3f) + 1)) st[#st + 1] = table.concat(t4) lln = lln + 4 if lln > maxlln then st[#st+1] = ""; lln = 1 end end local llx = #st if st[llx] == "" then llx = llx - 1 end if rn == 2 then st[llx] = string.gsub(st[llx], ".$", "=") elseif rn == 1 then st[llx] = string.gsub(st[llx], "..$", "==") end return table.concat(st) end local function encrypt_shell(Input_shell) local Str_Used = {} local function random_str(len)--随机 local res = {} for i = 1, len do local t = math.random(1, 2) if t == 1 then res[#res + 1] = string.char(math.random(65, 90)) else res[#res + 1] = string.char(math.random(97, 122)) end end return table.concat(res) end local t = {} local r = {} for i = 1, 9 do Str_Used[i] = random_str(33) end local _ = 0 for i in string.gmatch(Input_shell, string.format("([^%s]+)", "\n")) do local S_random = "" for k = 1, 15 do S_random = S_random .. string.char(math.random(225, 255)) end -- local S_random = string.char(math.random(225, 255) local encrypt = Base64_encrypt(i .. "\n") local math_Sub = math.random(1, #encrypt) local Sub = string.sub(encrypt, math_Sub, math_Sub) encrypt = encrypt:gsub(Sub, S_random) t[#t + 1] = "\"" .. encrypt .. "\"" r[#r + 1] = Base64_encrypt(Str_Used[3] .. " $" .. Str_Used[1] .. " " .. _ .. " \"" .. Sub .. "\" \"" .. S_random .. "\"") _ = _ + 1 end local Shell_encrypt = {} Shell_encrypt[#Shell_encrypt + 1] = Str_Used[4] .. "=$2" Shell_encrypt[#Shell_encrypt + 1] = Str_Used[5] .. "=${" .. Str_Used[1] .. "[$" .. Str_Used[4] .. "]}" Shell_encrypt[#Shell_encrypt + 1] = Str_Used[6] .. "=$(echo $" .. Str_Used[5] .. "| sed \"s/$4/$3/g\")" Shell_encrypt[#Shell_encrypt + 1] = Str_Used[7] .. "=$(echo $" .. Str_Used[6] .. "|base64 -d)" Shell_encrypt[#Shell_encrypt + 1] = "eval $(echo " .. Base64_encrypt(Str_Used[2] .. " $" .. Str_Used[7]) .. "|base64 -d)" if A_base then return Str_Used[1] .. "=(" .. table.concat(t, " ") .. ")\neval $(echo " .. Base64_encrypt(Str_Used[8] .. "=\"\"\n") .. "|base64 -d)\n" .. Str_Used[2] .. "()\n{\n\t" .. Str_Used[9] .. "=\"\n\"\neval $(echo " .. Base64_encrypt(Str_Used[8] .. "=$" .. Str_Used[8] .. "$" .. Str_Used[9] .. "$@") .. "|base64 -d)\n}\n" .. Str_Used[3] .. "()\n{\n\t" .. table.concat(Shell_encrypt, "\n\t") .. "\n}\n\neval $(echo " .. table.concat(r, "|base64 -d)\neval $(echo ") .. "|base64 -d)\neval $(echo " .. Base64_encrypt("eval \"$" .. Str_Used[8] .. "\"") .. "|base64 -d)" else return Str_Used[1] .. "=(" .. table.concat(t, " ") .. ")" .. "\n" .. Str_Used[2] .. "()\n{\n\teval $(echo " .. Base64_encrypt("eval $@") .. "|base64 -d)\n}\n" .. Str_Used[3] .. "()\n{\n\t" .. table.concat(Shell_encrypt, "\n\t") .. "\n}\n\neval $(echo " .. table.concat(r, "|base64 -d)\neval $(echo ") .. "|base64 -d)" end end local tt = gg.prompt({"文件"}, {file_path}, {"file"}) if tt then file_path = tt[1] local t = io.open(tt[1], "r") if t then gg.saveVariable({tt[1]}, config) t = t:read("*a") if enc_random then t = Shell_random(t) end if enc_Base then t = encrypt_shell(t) end io.open(tt[1] .. ".sh", "w"):write(t) end end --BY:青衫白衣