You are on page 1of 10

English | Vietnamese

Nội Quy Diễn đàn Portal


Danh sách thành viên Thống kê Tìm kiếm Phòng đọc

Đăng ký Đăng nhập [ http | https ]

Diễn đàn chính Thảo luận virus, trojan, spyware, worm... TUT: Chỉ xài DOS COMMANDS diệt virus

07/02/2009 03:36:31 (+0700) | #1


[Hỏi đáp] TUT: Chỉ xài DOS COMMANDS diệt virus 168579

Joined: 29/12/2008 12:17:36


Bài gởi: 100
w4s.info Offline
Member
0

Coi như máy tính của ta đơ đơ và ta làm trong DOS (Boot in DOS)
(Thanks to kamikazeq for ur question in virusvn)

Loại 1. Giải quyết loại:

Loại 2. Giải quyết loại:

G:\TaiLieu\
G:\TaiLieu\TaiLieu.exe

G:\TaiLieu\Excel\
G:\TaiLieu\Excel\Excel.exe

Scan trong ổ I:\ (làm ví dụ)


@echo off
for /r I:\ %%i in (.) do if exist %%~fi.exe (
cd %%~pi
for %%j in (%%~ni.exe) do if %%~zj == 18458 echo %%~zj %%~fj )

pause
Trước tiên các bạn cần nắm FOR COMMAND. Khi search bằng for theo giá trị (.) tức là chỉ tìm items định dạng thư
mục (folder). Nếu thay (.) thành (*.*) là chỉ tìm file, nếu thay bằng ( * ) là tìm tất cả file và folder

for /r I:\ %%i in (.) do if exist %%~fi.exe


là tìm theo thư mục, vì vậy giá trị trả về là các thư mục, do đó giá trị get_size %%~zi luôn bằng 0
Muốn so sánh theo size (tránh del nhầm) thì

cd %%~pi
để di chuyển đến thư mục chứa thư mục đang scan, dùng xử loại virus 1
cd %%i
để di chuyển vào trong thư mục đang scan, dùng xử loại 2

Sau khi di chuyển ta thực hiện scan trong thư mục đó các file exe có tên trùng với thư mục đang scan (giá trị %
%~ni.exe) và có size bằng virus size
Code:
for %%j in (%%~ni.exe) do if %%~zj == 18458 echo %%~zj %%~fj

lệnh này chỉ scan trong thư mục hiện thời chứ k scan thư mục con
Ta lọc các file/folder có %%~ni.exe sau đó kiểm tra size có bằng 18458 (bytes) hay k?
Nếu có thì echo %%~zj %%~fj
Thay cho echo như trên bạn muốn làm gì thì tùy, del chẳng hạn %%~zj là size của nó, %%~fj là full_path của

Đây chỉ là với các virus cũ, một số con mới hơn ngoài tạo hàng giả còn tạo chính nó trong thư mục ấy, khi đó
không có tên thư mục giống nó và
Code:
for %%j in (%%~ni.exe) do if %%~zj == 18458 echo %%~zj %%~fj

sẽ trả về kết quả không có nó

Xử lý:
Code:
for %%j in (*.exe) do if %%~zj == 18458 echo %%~zj %%~fj

ta quét toàn bộ các file exe sau đó so sánh dung lượng. Công việc này sẽ lâu hơn vì nhiều file trả về hơn.

Nếu virus k chỉ tạo chính nó (exe file) mà còn tạo những file định dạng khác, tên khác? vd virus.com, virus.pif...
Xử:
Code:
for %%j in (*.*) do if %%~zj == 18458 echo %%~zj %%~fj

Ta scan toàn bộ các file ! Tất nhiên sẽ càng lâu hơn.


Nhược điểm: Vẫn có tình trạng xóa nhầm vì nếu chỉ kiểm tra dung lượng thôi là chưa đủ. Số lượng file cùng định
dạng (exe chẳng hạn) có cùng dung lượng là ít nhưng không phải không có. Cần kiểm tra signature của virus, cái
này DOS không làm được

Các bạn chú ý dấu mở "(" (ở cuối ấy)


for /r I:\ %%i in (.) do if exist %%~fi.exe (

và dấu đóng ")" (cũng ở cuối)


for %%j in (%%~ni.exe) do if %%~zj == 18458 echo %%~zj %%~fj )

là để tách một nhóm lệnh ra từng dòng (cái này ai học lập trình rồi sẽ biết ngay) vì nếu để trên một dòng thì error
ngay

Cuối cùng nên có lệnh PAUSE để xem nó đã làm gì, tùy bạn muốn tạo/xem log thế nào cũng đc
Recommend: Upper All chars

Tui nêu một vài vấn đề anh em bàn thêm, cũng đơn giản nếu linh động một chút:
Trường hợp
\folder1\folder11\
\folder1\folder12.exe
trong khi không tồn tại
\folder1\folder12

vậy khi scan, câu lệnh if exist... sẽ bỏ qua folder12 luôn, vậy có sót k? giải quyết?

Nếu là
\folder11\
\folder12.exe
trong khi không tồn tại
\folder12

thì sao?

Anh em cho ý kiến luôn nếu chỉ dùng một câu sau thay cho tất cả:
Code:
for /r I:\ %%j in (*.*) do if %%~zj == 18458 echo %%~zj %%~fj

việc echo hay del là tùy bạn (như đã nói trên), cái cần phân tích là ưu điểm và nhược điểm của cách này
Bạn nên để ý đến tốc độ chạy, khả năng bắt nhầm hay không, có sót không,...

Mời anh em bàn thêm


Multiple Bootable DVD - Win7 - XP SP2 - XP Live CD - Hiren 9.9 ...:
[url]http://www.hvaonline.net/hvaonline/posts/list/30744.hva[/url]
07/02/2009 03:57:22 (+0700) | #2
[Hỏi đáp] Re: TUT: Chỉ xài DOS COMMANDS diệt virus 168581

Joined: 29/12/2008 12:17:36


Bài gởi: 100
w4s.info Offline
Member
0

Quên nói thêm, ta chỉ làm công việc tìm và xoá file virus (loại worm) chứ chưa can thiệp tới sửa chữa registry,
system
Multiple Bootable DVD - Win7 - XP SP2 - XP Live CD - Hiren 9.9 ...:
[url]http://www.hvaonline.net/hvaonline/posts/list/30744.hva[/url]

07/02/2009 08:47:56 (+0700) | #3


[Hỏi đáp] Re: TUT: Chỉ xài DOS COMMANDS diệt virus 168596

Joined: 26/08/2007 02:53:39


Bài gởi: 998
jforum3000 Đến từ: TP.HCM
Member Online
0

Bạn có thể thêm một số trường hợp ví dụ khác được không (mình vẫn chưa rõ cái cấu trúc lệnh tổng quát của
nó): chẳng hạn tìm các file theo điều kiện thuộc tính tập tin, theo ngày giờ chinh sửa hoặc mô phỏng theo các
đặc điểm của một tập tin nào đó, giới hạn kí tự tên tập tin ...
Đánh cho đời mãi mãi một màu xanh ...

08/02/2009 17:07:04 (+0700) | #4


[Hỏi đáp] Re: TUT: Chỉ xài DOS COMMANDS diệt virus 168768

Joined: 29/12/2008 12:17:36


Bài gởi: 100
w4s.info Offline
Member
0

Bạn chỉ cần vào DOS gõ


Code:
là biết ngay mà

J:\>for /?
Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

%variable Specifies a single letter replaceable parameter.


(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead


of %variable. Variable names are case sensitive, so %i is different
from %I.

If Command Extensions are enabled, the following additional


forms of the FOR command are supported:

FOR /D %variable IN (set) DO command [command-parameters]

If set contains wildcards, then specifies to match against directory


names instead of file names.

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

Walks the directory tree rooted at [drive:]path, executing the FOR


statement in each directory of the tree. If no directory
specification is specified after /R then the current directory is
assumed. If set is just a single period (.) character then it
will just enumerate the directory tree.

FOR /L %variable IN (start,step,end) DO command [command-parameters]

The set is a sequence of numbers from start to end, by step amount.


So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
generate the sequence (5 4 3 2 1)

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]


FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

or, if usebackq option present:

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]


FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

filenameset is one or more file names. Each file is opened, read


and processed before going on to the next file in filenameset.
Processing consists of reading in the file, breaking it up into
individual lines of text and then parsing each line into zero or
more tokens. The body of the for loop is then called with the
variable value(s) set to the found token string(s). By default, /F
passes the first blank separated token from each line of each file.
Blank lines are skipped. You can override the default parsing
behavior by specifying the optional "options" parameter. This
is a quoted string which contains one or more keywords to specify
different parsing options. The keywords are:

eol=c - specifies an end of line comment character


(just one)
skip=n - specifies the number of lines to skip at the
beginning of the file.
delims=xxx - specifies a delimiter set. This replaces the
default delimiter set of space and tab.
tokens=x,y,m-n - specifies which tokens from each line are to
be passed to the for body for each iteration.
This will cause additional variable names to
be allocated. The m-n form is a range,
specifying the mth through the nth tokens. If
the last character in the tokens= string is an
asterisk, then an additional variable is
allocated and receives the remaining text on
the line after the last token parsed.
usebackq - specifies that the new semantics are in force,
where a back quoted string is executed as a
command and a single quoted string is a
literal string command and allows the use of
double quotes to quote file names in
filenameset.

Some examples might help:

FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k

would parse each line in myfile.txt, ignoring lines that begin with
a semicolon, passing the 2nd and 3rd token from each line to the for
body, with tokens delimited by commas and/or spaces. Notice the for
body statements reference %i to get the 2nd token, %j to get the
3rd token, and %k to get all remaining tokens after the 3rd. For
file names that contain spaces, you need to quote the filenames with
double quotes. In order to use double quotes in this manner, you also
need to use the usebackq option, otherwise the double quotes will be
interpreted as defining a literal string to parse.

%i is explicitly declared in the for statement and the %j and %k


are implicitly declared via the tokens= option. You can specify up
to 26 tokens via the tokens= line, provided it does not cause an
attempt to declare a variable higher than the letter 'z' or 'Z'.
Remember, FOR variables are single-letter, case sensitive, global,
and you can't have more than 52 total active at any one time.

You can also use the FOR /F parsing logic on an immediate string, by
making the filenameset between the parenthesis a quoted string,
using single quote characters. It will be treated as a single line
of input from a file and parsed.

Finally, you can use the FOR /F command to parse the output of a
command. You do this by making the filenameset between the
parenthesis a back quoted string. It will be treated as a command
line, which is passed to a child CMD.EXE and the output is captured
into memory and parsed as if it was a file. So the following
example:

FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i

would enumerate the environment variable names in the current


environment.
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")


%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only


%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line

In the above examples %I and PATH can be replaced by other valid


values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.

Multiple Bootable DVD - Win7 - XP SP2 - XP Live CD - Hiren 9.9 ...:


[url]http://www.hvaonline.net/hvaonline/posts/list/30744.hva[/url]

08/02/2009 20:07:59 (+0700) | #5


[Hỏi đáp] Re: TUT: Chỉ xài DOS COMMANDS diệt virus 168780

Joined: 26/08/2007 02:53:39


Bài gởi: 998
jforum3000 Đến từ: TP.HCM
Member Online
0

w4s.info wrote:
FOR /?
là biết ngay mà

Cám ơn bác, do đang ở Linux nên không có DOS, uhm, để mình cài DOSBOX vào rồi test thử vậy.
Đánh cho đời mãi mãi một màu xanh ...

11/02/2009 14:06:20 (+0700) | #6


[Hỏi đáp] Re: TUT: Chỉ xài DOS COMMANDS diệt virus 169134

Joined: 31/01/2007 15:29:12


Bài gởi: 103
hongtham Đến từ: Bà Rịa
Member Offline
0

Code:
for /r I:\ %%i in (.) do if exist %%~fi.exe (
cd %%~pi
for %%j in (%%~ni.exe) do if %%~zj == 18458 del %%~zj %%~fj )

cái này đáng để học hỏi


không cần lệnh pause vì trong dos thực lệnh pause chỉ dùng khi nạp các thiết bị ngoài.
\folder1\folder11\
\folder1\folder12.exe
trong khi không tồn tại
\folder1\folder12

vậy khi scan, câu lệnh if exist... sẽ bỏ qua folder12 luôn, vậy có sót k? giải quyết?

thực tế là batch file của bạn đã giải quyết hoàn hảo yêu cầu của kamikazeq rồi
bởi lệnh for search tên thư mục và đường dẫn rồi thêm đuôi .exe vào giá trị tập hợp của nó do đó nếu không tồn
tại thư mục folder12 thì trong tập hợp cũng không có đường dẫn folder12.exe luôn thì làm sao xóa tự động được.

Giải quyết theo cách bên dưới của bạn vậy là ổn rồi : hiếm có trường hợp hai file khác nhau trùng size lắm
Rảnh tay viết một batch theo cách của bạn nhưng nhập tên ổ đĩa và size properties từ bàn phím và chạy trên cả
windows
Code:
@echo off
if "1+%1"=="1+/?" goto help
if .==.%1 goto windows
for %%D in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if %1==%%D goto
size
for %%L in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if %1==%%L goto
size
goto warning
:windows
echo Enter disk name:
SET /P drive=
if .==.%drive% goto warning
for %%D in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if %drive%==%%D
goto size
for %%L in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if %drive%==%%L
goto size
goto warning
:size
if .==.%1 echo You entered %drive%
if .==.%1 echo.
if not .==.%2 goto input
echo Enter file size:
SET /P size=
if .==.%size% goto warning
echo You entered %size%
if not .==.%1 set drive=%1
goto search
:input
set drive=%1
set size=%2
:search
for %%k in (.) do set fullpath=%%~fk
%drive%:
cd \
for /r %drive%:\ %%i in (.) do if exist %%~fi.exe (
cd %%~pi
for %%j in (%%~ni.exe) do if %%~zj == %size% del /f %%~zj %%~fj )
if not errorlevel 1 echo successful
cd /d %fullpath%
set fullpath=
set drive=
set size=
goto end
:warning
echo error
:help
echo Usage: %0 [Drive] [size]
:end
echo on

note: Đã chỉnh theo yêu cầu của w4s.info


11/02/2009 22:45:13 (+0700) | #7
[Hỏi đáp] Re: TUT: Chỉ xài DOS COMMANDS diệt virus 169185

Joined: 29/12/2008 12:17:36


Bài gởi: 100
w4s.info Offline
Member
0

Bros chú ý nhé:

%%~zj là size của file còn %%~fj là full_path, nên sửa lại lệnh del cho phù hợp, del luôn cả file định dạng
Readonly

Code:
Del /?

Multiple Bootable DVD - Win7 - XP SP2 - XP Live CD - Hiren 9.9 ...:


[url]http://www.hvaonline.net/hvaonline/posts/list/30744.hva[/url]

Chuyển đến:

Các thành viên đang hiện diện ở đây

2 Khách

Powered by JForum - Extended by HVAOnline


hvaonline.net | hvaforum.net | hvazone.net | hvanews.net | vnhacker.org
1999 - 2009 © v2009|2707|218|

You might also like