ISC2016训练赛-phrackCTF
Smali:
类型:Reverse
**题目描述:都说学好Smali是学习Android逆向的基础,现在刚好有一个smali文件,大家一起分析一下吧~~ **
解题方法:将题目附件下载下来之后发现是一个.smali文件,将它放进jadx-gui里面进行一下反编译得到:
package net.bluelotus.tomorrow.easyandroid;
import android.util.Base64;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
/* loaded from: C:\Users\76649\AppData\Local\Temp\jadx-3466106792537216802.dex */
public class Crackme {
private String str2 = "cGhyYWNrICBjdGYgMjAxNg==";
public Crackme() {
GetFlag("sSNnx1UKbYrA1+MOrdtDTA==");
}
private String GetFlag(String str) {
byte[] content = Base64.decode(str.getBytes(), 0);//这里将getflag里的值进行base64解密
String kk = new String(Base64.decode(this.str2.getBytes(), 0));//这里将str2里面的值进行base64解码
System.out.println(decrypt(content, kk));
return null;
}
private String decrypt(byte[] content, String password) { //将解码后的Getflag和str2传下来
try {
byte[] keyStr = password.getBytes();
SecretKeySpec key = new SecretKeySpec(keyStr, "AES"); //将解码后的str2作为AES的密钥
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");//进行AES编码解码
cipher.init(2, key);
byte[] result = cipher.doFinal(content); //将解码后的Getflag作为AES的密文
String m = new String(result);
return m;
} catch (InvalidKeyException | NoSuchAlgorithmException | BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException e) {
e.printStackTrace();
return null;
}
}
}
简单分析完这段代码之后,我们发现str2进行base64解码可以得到一串字符串,然后Getflag里面的值经过base64解码得到的是一串乱码,所以这里就比较符合上面分析出来的,str2可能是AES的密钥,Getflag是AES的密文
所以这里我们可以用python脚本来进行解码:
from Crypto.Cipher import AES
import base64
key = base64.b64decode("cGhyYWNrICBjdGYgMjAxNg==")
str1 = base64.b64decode("sSNnx1UKbYrA1+MOrdtDTA==")
print(str1)
cryptor = AES.new(key, AES.MODE_ECB)
print(key)
result = cryptor.decrypt(str1)
print(result)
解码得到flag:
PCTF{Sm4liRiver}
标签:AES,String,str2,解码,base64,phrackCTF,训练赛,import,Smali From: https://www.cnblogs.com/xyweiwen/p/18102323