FridaLab Solution
My FridaLab Solution 01 ~ 08
Intro
์๋๋ก์ด๋ ๊ณต๋ถํด๋ณด๊ณ ์ถ์ด์ ์๋๋ก์ด๋ ํํน ํด์ธ Frida๋ฅผ ์ข ์ตํ๋ณด๊ธฐ ์ํด FriaLab ์๊ฒ์(?)์ ํ์ด๋ณด์๋ค.
- Android ์๋ฎฌ๋ ์ดํฐ ๋ฒ์ : Android 13.0 (โTiramisuโ) | arm64
- Frida Version: 16.7.14
- Python 3.11.12
Frida Server 16.7.14 ๋ฒ์ ์ python 3.12 ๋ฒ์ ์ด์์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ ๋๊ฐ ์๋ค. ํ์ด์ฌ ๋ฒ์ ์ 3.11 ์ดํ๋ก
๋ค์ด๊ทธ๋ ์ด๋ํด์ ์ฌ์ฉํ๋ ๊ฒ์ ์ถ์ฒํ๋ค.
Challenge 01
1
2
3
4
5
6
7
8
9
package uk.rossmarks.fridalab;
public class challenge_01 {
static int chall01;
public static int getChall01Int() {
return chall01;
}
}
Mainactivity์ onCreate๋ฉ์๋๋ฅผ ๋ณด๋ฉด, getChall01Int์ ๋ฆฌํด๊ฐ์ 1๋ก ๋ง๋ค์ด์ผ ํ๋ค.
1
2
3
4
5
6
7
setImmediate(function() {
Java.perform(function(){
var ClassChall01 = Java.use("uk.rossmarks.fridalab.challenge_01");
ClassChall01.chall01.value = 1;
console.log("[+] Challenge_01 Solved");
})
})
challenge_01์ ๊ฒฝ์ฐ์๋ ์ธ์คํด์คํ๋์ง ์์ ํด๋์ค์ด๊ธฐ ๋๋ฌธ์ Java.use()๋ก ํด๋์ค๋ฅผ ๊ฐ์ ธ์ ๋ด๋ถ ๋ณ์ ๊ฐ์ 1๋ก ๋ฐ๊ฟ์ฃผ์๋ค.
Challenge 02
1
2
3
private void chall02() {
this.completeArr[1] = 1;
}
MainActivityํด๋์ค ๋ด๋ถ์ ์กด์ฌํ๋ method์ธ chall02()๋ฅผ ์คํ๋ง ํ๋ฉด ๋๋ค.
1
2
3
4
5
6
7
8
9
10
setImmediate(function() {
Java.choose("uk.rossmarks.fridalab.MainActivity", {
onMatch : function (instance) {
instance.chall02();
},
onComplete : function () {
console.log("[+] Challenge_02 Solved");
}
})
})
MainActivity๋ ์๋๋ก์ด๋๊ฐ ์คํ๋๋ฉด ์๋์ผ๋ก ์ธ์คํด์คํ ๋๋ค. ๊ทธ๋์ Java.choose()๋ก MainActivity์ ์ธ์คํด์ค๋ฅผ ๊ฐ์ ธ์ chall02()๋ฅผ ์คํ์ํค๋ฉด ๋๋ค.
Challenge 03
1
2
3
public boolean chall03() {
return false;
}
MainActivityํด๋์ค ๋ด๋ถ์ ์กด์ฌํ๋ method์ธ chall03()์ ๋ฆฌํด๊ฐ์ true๋ก ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
setImmediate(function() {
Java.choose("uk.rossmarks.fridalab.MainActivity", {
onMatch : function (instance) {
instance.chall03.implementation = function() {
return true;
}
},
onComplete : function () {
console.log("[+] Challenge_03 Solved");
}
})
})
์ธ์คํด์ค๋ฅผ ๊ฐ์ ธ์จ ํ chall03๋ฉ์๋๋ฅผ implementation๋ก ์ค๋ฒ๋ผ์ด๋ ํ์ฌ ๋ฌด์กฐ๊ฑด true๋ฅผ ๋ฆฌํดํ๋๋ก ํ๋ค.
Challenge 04
1
2
3
4
5
public void chall04(String str) {
if (str.equals("frida")) {
this.completeArr[3] = 1;
}
}
MainActivityํด๋์ค ๋ด๋ถ์ ์กด์ฌํ๋ method์ธ chall04()๋ฅผ ํธ์ถํ ๋ frida๋ผ๋ ๋ฌธ์์ด์ ๋๊ฒจ์ฃผ๋ฉด ๋๋ค.
1
2
3
4
5
6
7
8
9
10
setImmediate(function() {
Java.choose("uk.rossmarks.fridalab.MainActivity", {
onMatch : function (instnace) {
instnace.chall04("frida");
},
onComplete : function () {
console.log("[+] Challenge_04 Solved");
}
})
})
์ธ์คํด์ค๋ฅผ ๊ฐ์ ธ์ chall04๋ฅผ ๊ฐ์ ธ์จ ํ frida๋ฅผ ์ ๋ฌํ๋ฉด ๋๋ค.
Challenge 05
1
2
3
4
5
6
7
public void chall05(String str) {
if (str.equals("frida")) {
this.completeArr[4] = 1;
} else {
this.completeArr[4] = 0;
}
}
4๋ฒ๋ฌธ์ ์ ๋น์ทํ์ง๋ง ์ฝ๊ฐ ๋ค๋ฅด๋ค. onCreate์ onClick๋ฉ์๋๋ฅผ ๋ณด๋ฉด Confirm ๋ฒํผ์ ํด๋ฆญํ ๋ ๋ง๋ค notfrida!๋ฅผ ์ ๋ฌํ๋ค. ๋ฐ๋ผ์ ๋งค ์์ฒญ ๋ ๋ง๋ค firda๋ฅผ ์ ๋ฌํ๋๋ก ํด์ผํ๋ค.
1
2
3
4
5
6
7
8
9
setImmediate(function() {
Java.perform(function() {
let MainClass = Java.use('uk.rossmarks.fridalab.MainActivity');
MainClass.chall05.implementation = function() {
this.chall05("frida");
console.log("[+] Challenge_05 Solved");
}
})
})
Java.choose๋ก MainActivity์ ์ธ์คํด์ค๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฐฉ์์ ํ๋ฒ๋ง ์คํ๋๊ธฐ ๋๋ฌธ์ ํ๋ก์ธ์ค ์คํ ์ค์ ๋ฒํผ์ ํ๋ฒ ๋ ํด๋ฆญํ๋ฉด notfrida!๊ฐ ์ ๋ฌ๋๋ค.
๋ฐ๋ผ์ Java.use๋ก MainActivity ํด๋์ค๋ฅผ ๊ฐ์ ธ์ chall05 ์์ฒด๋ฅผ ์ค๋ฒ๋ผ์ด๋ ํ์ฌ, Frida ํ๋ก์ธ์ค๊ฐ ๋์๊ฐ๊ณ ์๋ ํ chall05("frida")๊ฐ ์คํ๋๋๋ก ํ๋ฉด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ค.
Challenge 06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package uk.rossmarks.fridalab;
public class challenge_06 {
static int chall06;
static long timeStart;
public static void startTime() {
timeStart = System.currentTimeMillis();
}
public static boolean confirmChall06(int i) {
return i == chall06 && System.currentTimeMillis() > timeStart + 10000;
}
public static void addChall06(int i) {
chall06 += i;
if (chall06 > 9000) {
chall06 = i;
}
}
}
confirmChall06์ ๋ฆฌํด๊ฐ์ 1๋ก ๋ง๋ค์ด์ผ ํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
// onCreate
challenge_06.startTime();
challenge_06.addChall06(new Random().nextInt(50) + 1);
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
int nextInt = new Random().nextInt(50) + 1;
challenge_06.addChall06(nextInt);
Integer.toString(nextInt);
}
}, 0L, 1000L);
onCreate์์ ์ ์ฝ๋๊ฐ ์คํ๋๋ค. ์ด์ ํจ๊ป ๋ฌธ์ ์ฝ๋๋ฅผ ๋ถ์ํด๋ณด์.
- startTime๋ฅผ ํธ์ถํ์ฌ ํ์ฌ ์๊ฐ์
challenge_06ํด๋์ค์timeStart๋ณ์์ ์ ์ฅ - 10์ด๋ง๋ค 0 ~ 50 ์ฌ์ด์ ์ ์๋ฅผ
challenge_06ํด๋์ค์chall06๋ณ์์ ๋ํจ
๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์๋ ์๋ ๋ ๊ฐ์ ์กฐ๊ฑด์ ๋ง์ถฐ์ผ ํ๋ค.
- 10์ด ํ
chall06์ ๊ฐ์ ๋ง์ถ๋ค. confirmChall06์ ์คํํ ๋์ ์๊ฐ์ดtimeStart๋ณ์์ ์ ์ฅ๋ ์๊ฐ๋ณด๋ค 10์ด ํ์ฌ์ผ ํ๋ค.
๊ทธ๋ ๋ค๋ฉด setTimeout(function(){}, 10000)๋ก 10์ด๋ฅผ ๊ธฐ๋ค๋ฆฐ ํ chall06๋ณ์ ๊ฐ์ ํํนํด ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ๊ณผ timeStart๋ณ์๋ฅผ ํํนํด ์กฐ์ํ๋ ๋ฐฉ๋ฒ ์ด๋ ๊ฒ ๋ ๊ฐ์ง๊ฐ ์์ ์ ์๋ค. ๋๋ฒ์งธ ๋ฐฉ๋ฒ์ผ๋ก ํ์ด๋ณด๊ฒ ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
setImmediate(function(){
Java.perform(function(){
Java.choose("uk.rossmarks.fridalab.MainActivity", {
onMatch : function(instnace){
let ClassChall06 = Java.use("uk.rossmarks.fridalab.challenge_06")
ClassChall06.timeStart.value = -10000
ClassChall06.addChall06.implementation = function(i) {
this.addChall06(i);
}
instnace.chall06(Number(ClassChall06.chall06.value));
},
onComplete : function(){
console.log("[+] Challenge_06 Solved");
}
})
})
});
Challenge 07
1
2
3
4
5
6
7
8
9
10
11
12
13
package uk.rossmarks.fridalab;
public class challenge_07 {
static String chall07;
public static void setChall07() {
chall07 = BuildConfig.FLAVOR + (((int) (Math.random() * 9000.0d)) + 1000);
}
public static boolean check07Pin(String str) {
return str.equals(chall07);
}
}
chall07์ ๊ฐ์ ๋ง์ถฐ์ผ ํ๋ฆฌ๋ ๋ฌธ์ ๋ค. BuildConfig.FLAVOR๋ ๋น ๋ฌธ์์ด์ด๊ธฐ์ ์ ๊ฒฝ ์ธ ํ์ ์๊ณ , (((int) (Math.random() * 9000.0d)) + 1000);์ ๊ฐ์ 1000 ~ 9999 ์ฌ์ด์ ๊ฐ์ด๋ ๋ธ๋ฃจํธํฌ์ฑํ์ฌ ํด๊ฒฐํ์.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
setImmediate(function() {
Java.perform(function() {
Java.choose("uk.rossmarks.fridalab.MainActivity", {
onMatch: function (instance){
let ClassChall07 = Java.use("uk.rossmarks.fridalab.challenge_07")
for (let i=1000; i<=9999; i++){
if(ClassChall07.check07Pin(i.toString())){
instance.chall07(String(i));
console.log("[+] Challenge_07 Solved : " + i);
break;
}
}
},
onComplete : function(){}
})
})
})
๋ธ๋ฃจํธํฌ์ฑํ์ฌ ์๋ง์ ๊ฐ์ ํ์ธํ ํ chall07์ ๊ทธ ๊ฐ๊ณผ ํจ๊ป ์คํํ๋ค.
Challenge 08
1
2
3
public boolean chall08() {
return ((String) ((Button) findViewById(R.id.check)).getText()).equals("Confirm");
}
๋ง์ง๋ง ๋ฌธ์ ๋ค. ํ์ฌ ํ์ธ๋ฒํผ ์ด๋ฆ์ธ Check๋ฅผ Confirm์ผ๋ก ๋ณ๊ฒฝํด์ฃผ๋ฉด ๋๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
setImmediate(function() {
Java.perform(function() {
Java.choose("uk.rossmarks.fridalab.MainActivity", {
onMatch: function (instance){
let button = Java.use("android.widget.Button")
// public static final int check = 0x7f07002f;
let check = instance.findViewById(0x7f07002f)
let checkButton = Java.cast(check, button)
let String = Java.use("java.lang.String")
checkButton.setText(String.$new("Confirm"))
},
onComplete : function(){
console.log("[+] Challenge_08 Solved");
}
})
})
})
์ ์ฝ๋๋ฅผ ์คํํ๋ฉด Check ๋ฒํผ์ด Confirm ๋ฒํผ์ผ๋ก ๋ฐ๋๋ค.
All Solved
์ด๋ ๊ฒ ๋ชจ๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค. FridaLab์ Frdia ํด์ ์ฌ์ฉํ๊ธฐ ์ํ ๊ธฐ์ด์ ์ธ ๋ฌธ์ ์ด๊ธฐ์ ๋ค๋ฅธ ์๊ฒ์๋ค์ ํ์ด๋ณด๊ณ ๋ค์ํ APK๋ฅผ ๋ถ์ํด๋ด์ผ ํ ๊ฒ ๊ฐ๋ค.


