XCTF-phoenix100
阿新 • • 發佈:2020-07-28
前期工作
查殼無殼,介面是普通的輸入flag點選驗證
逆向分析
檔案結構只有一個MainActively,檢視MainActively程式碼
public class MainActivity extends AppCompatActivity { EditText etFlag; public native String encrypt(String str); public native String getFlag(); static { System.loadLibrary("phcm"); } /* access modifiers changed from: protected */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView((int) R.layout.activity_main); this.etFlag = (EditText) findViewById(R.id.flag_edit); } public void onGoClick(View v) { if (getSecret(getFlag()).equals(getSecret(encrypt(this.etFlag.getText().toString())))) { Toast.makeText(this, "Success", 1).show(); } else { Toast.makeText(this, "Failed", 1).show(); } } public String getSecret(String string) { try { byte[] hash = MessageDigest.getInstance(encrypt("KE3TLNE6M43EK4GM34LKMLETG").substring(5, 8)).digest(string.getBytes("UTF-8")); if (hash != null) { StringBuilder hex = new StringBuilder(hash.length * 2); for (byte b : hash) { if ((b & 255) < 16) { hex.append("0"); } hex.append(Integer.toHexString(b & 255)); } return hex.toString(); } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e2) { e2.printStackTrace(); } return null; } }
有兩個native方法,getSecret方法中也呼叫了其中一個,所以還是先看看這兩個方法吧。
檢視字串,沒找到什麼可疑的字串,很簡單就找到了兩個方法。先看看encrypt吧。
昨天看到說不用匯入jni了,直接按y改結構就可以了。
encrypt程式碼,這裡要x86的so,不然引數個數有問題,原因不明。
可以看到就是字串每位-1。
回頭再看getSecret方法。
MessageDigest.getInstance(encrypt("KE3TLNE6M43EK4GM34LKMLETG").substring(5, 8)).digest(string.getBytes("UTF-8"));
這一句應該就是MD5加密了。
因為getFlag方法沒有引數只有返回值,直接Hook onGoClick方法檢視getFlag的返回值
ek`fz@q2^x/t^fn0mF^6/^rb`qanqntfg^E`hq|
既然兩邊都經過了getSecret函式,那不要管這個函式,只要讓兩邊的字串一樣即可。
指令碼簡單就不放了
flag
flag{Ar3_y0u_go1nG_70_scarborough_Fair}