目前有一種透過冒充來自匯豐銀行、勞埃德銀行、亞馬遜等的電子郵件發送病毒/木馬的活動。
木馬/病毒以應用程式/zip 附件形式發送。
我保存了一個這樣的 zip 文件,並將其解壓縮到我擁有的 ext4 文件系統上的 700 權限目錄中
為了使用clamscan
、avgscan
、 和進行掃描avast
,我保存了 zip 檔案並將其內容解壓縮到目錄「virus」中:
File: /home/users/miller/virus
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 809h/2057d Inode: 14155801 Links: 2
Access: (0700/drwx------) Uid: ( 1001/ miller) Gid: ( 1000/ users)
Access: 2013-10-03 12:57:47.484923866 +0200
Modify: 2013-10-03 12:57:46.684879168 +0200
Change: 2013-10-03 12:57:46.684879168 +0200
Birth: -
正如預期的那樣,我可以重命名該文件或將其刪除。該檔案的權限為 600,歸我所有:
$ stat virus.exe
File: virus.exe
Size: 61440 Blocks: 120 IO Block: 4096 regular file
Device: 809h/2057d Inode: 14155809 Links: 1
Access: (0600/-rw-------) Uid: ( 1001/ miller) Gid: ( 1000/ users)
Access: 2013-10-03 12:46:37.194541504 +0200
Modify: 2013-10-01 22:01:44.000000000 +0200
Change: 2013-10-03 13:19:09.263393591 +0200
Birth: -`
但任何讀取該文件或複製該文件的嘗試都會失敗。
$ file virus.exe
virus.exe: writable, regular file, no read permission`
cp virus.exe copy.exe
cp: cannot open virus.exe for reading: Operation not permitted`
lsattr virus.exe
lsattr: Operation not permitted While reading flags on virus.exe`
即使以 root 身分嘗試此操作也會失敗。
那麼如何才能使文件不可讀,即使它具有“rw 權限”,以及如何使其可讀以便使用avgscan
、clamscan
等掃描它avast
?
* 更正** (之前的評論是針對錯誤的zip檔)
附錄:執行clamscan
已儲存的附件 zip 檔案本身不會導致偵測到病毒/木馬/惡意軟體,可能是因為內部執行檔處於「不可讀取」狀態。
clamscanvirus.zipvirus.zip:好的
同樣avgscan
,也avast
無法偵測到任何惡意軟體。
這凸顯了能夠讀取提取的 exe 檔案的重要性,並表明clamscan
無法偵測惡意軟體。
zip 檔案的原始名稱為ORDER-N:N-1414559-3015133.zip
,可執行檔的原始名稱為Order details.exe
。
* 重要的附加資訊 *
回顧一下,如果使用者 miller 解壓縮 zip 文件,則會建立一個 exe 檔案:
60 -rw------- 1 miller users 61440 2013-10-01 22:01 Order details.exe
但這對使用者 miller 或 root 來說都是無法讀取的。
但是,如果 zip 檔案由 root 解壓縮,則 exe 檔案可由 root 讀取:
0 -rw-r--r-- 1 root root 61440 2013-10-01 22:01 Order details.exe
文件命令顯示如下:
[15:57] koala:{virus/}# file Order\ details.exe
Order details.exe: PE32 executable (GUI) Intel 80386, for MS Windows
那麼是什麼設定阻止普通用戶和 root 讀取用戶解壓縮的檔案呢?
root解壓縮後的文件:
$ lsattr Order\ details.exe
-------------e-- Order details.exe
手冊頁chattr
解釋:
The 'e' attribute indicates that the file is using extents for mapping
the blocks on disk. It may not be removed using chattr(1).
因此,在 ext2/3/4 檔案系統上存在一個 catch22 情況—檔案缺乏可讀性不能需要更改,解決方案是以 root 身份解壓縮 zip 存檔,以避免創建帶有“e”屬性的解壓縮文件,因為 Linux 解壓縮版本沒有忽略屬性開關。
如果使用者將zip檔案解壓縮到XFS檔案系統上,那麼它是可讀的,因為XFS不支援屬性設定機制。
以及何時avgscan
在 exe 檔案上運行:
$ avgscan Order\ details.exe
AVG command line Anti-Virus scanner
Copyright (c) 2013 AVG Technologies CZ
Virus database version: 3222/6719
Virus database release date: Thu, 03 Oct 2013 06:11:00 +0200
Order details.exe Found Luhe.Fiha.A
Files scanned : 1(1)
Infections found : 1(1)
所以這個故事的寓意是不要相信 avgscan
、avast
、 或clamscan
始終在 zip 檔案中尋找惡意軟體 - 始終對解壓縮的可執行檔進行掃描!
答案1
據我所知,確鑿無疑的命令是:
lsattr virus.exe
lsattr: Operation not permitted While reading flags on virus.exe
這基本上是說底層檔案系統不是EXT2/3/4。鑑於正常權限有時可能不是一個因素,並且文件屬性也可能不受支援。
例子
我有一個 NFS 安裝共享,如下所示。
$ pwd
/home/sam
如果我lsattr
反對它:
$ lsattr /home/sam/ 2>&1 | head -3
lsattr: Inappropriate ioctl for device While reading flags on /home/sam/dead.letter
lsattr: Inappropriate ioctl for device While reading flags on /home/sam/bashrc
lsattr: Inappropriate ioctl for device While reading flags on /home/sam/phillip_phillips_home.mp3
我的猜測是檔案系統拒絕您訪問它。