Automne's Shadow.

CTFZone 2018 Never ever be fooled to pay the ransomware! WriteUp

2018/08/05 Share

Android

拿到phonedump压缩包,解压后为一个Android备份文件好和一个提示文件。

automne

使用abe.jar来恢复备份文件内容。还原出一个压缩文件backup.tar。

automne

打开压缩包,有两个文件夹,apps和shared,其中前者包含很多app应用,后者的Download目录下下载了几个apk,在模拟器里安装测试,未见端倪。

automne

Camera目录下有几个可疑的加密文件。

automne

将apps目录下的所有应用翻了一遍,发现一个vdex文件,而且该应用的命名方式com.dfwgxc.zimcdwpealgy也很像恶意软件命名形式。

automne

在ubuntu 14.04里编译vdexExtractor,编译成功后对上面的vdex文件进行反编译。

automne

输出muquieljmg.apk_classes.dex文件。使用JEB打开

automne

最终在PkdGTfG类下发现上述发现的可疑后缀。

可以确定应用com.dfwgxc.zimcdwpealgy就是题中涉及到的勒索软件。

automne

其中函数faweifunhiunfg2uylbh8734gh778ghinegkrGln18hi8123(Context arg3)里将得到的imei号进行md5处理

automne

Md5处理

automne

上面获取到的md5编码和文件名一起作为参数,交由加密函数处理。

automne

主要加密/sdcard及其子目录下的文件(不处理以.xxx、.salt和.iv为后缀的文件)。

automne

加密函数核心代码

automne

同样给出了解密函数

automne

代码逻辑已经搞清楚了,而且imageinfo.txt已经包含了imei号。

automne

于是尝试破解加密后的文件。

使用java对应编写解密文件DecryRan.java,代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;

public class DecryRan {
public static void main(String args[]) throws Exception{
Decrypt(Mmd5("867562039629283"),"C://Users//Administrator//workspace//Test//src//IMG_20180101_071505.jpg.xxx");
System.out.println("done");
}

public static String Mmd5(String arg6) {
MessageDigest v0 = null;
try {
v0 = MessageDigest.getInstance("MD5");
}
catch(NoSuchAlgorithmException v2) {
v2.printStackTrace();
}
v0.update(arg6.getBytes(), 0, arg6.length());
return new BigInteger(1, v0.digest()).toString(16);
}

private static void Decrypt(String key, String filename) throws Exception {

FileInputStream v16 = new FileInputStream(filename.substring(0, filename.length() - 4) + ".salt");
byte[] v17 = new byte[8];
v16.read(v17);
v16.close();
FileInputStream v4 = new FileInputStream(filename.substring(0, filename.length() - 4) + ".iv");
byte[] v11 = new byte[16];
v4.read(v11);
v4.close();
SecretKeySpec v18 = new SecretKeySpec(SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec(key.toCharArray(), v17, 65536, 256)).getEncoded(), "AES");
Cipher v6 = Cipher.getInstance("AES/CBC/PKCS5Padding");
v6.init(2, v18, new IvParameterSpec(v11));
FileInputStream v8 = new FileInputStream(filename);
FileOutputStream v9 = new FileOutputStream(filename + ".decrypted");
byte[] v7 = new byte[64];
while(true) {
int v10 = v8.read(v7);
if(v10 == -1) {
break;
}
byte[] v5 = v6.update(v7, 0, v10);
if(v5 == null) {
continue;
}
v9.write(v5);
}
byte[] v15 = v6.doFinal();
if(v15 != null) {
v9.write(v15);
}
v8.close();
v9.flush();
v9.close();
}
}

运行报出Illegal key size错误,因为密钥长度是受限制的, java运行时环境读到的是受限的policy文件. 文件位于${java_home}/jre/lib/security, 这种限制是因为美国对软件出口的控制.

automne

解决办法:拷贝JCE无限制权限策略文件并进行替换,替换jdk目录下的jre。

automne

1
2
javac DecryRan.java
java DecryRan

得到以.decrypted结尾的文件,修改后缀,得到一张图片,其中包含flag。

automne

CATALOG