> For the complete documentation index, see [llms.txt](https://docs.cooku222.kr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cooku222.kr/security/mobile/frida-lab/frida-labs-0x3.md).

# Frida-Labs 0x3

출처: <https://github.com/DERE-ad2001/Frida-Labs/tree/main/Frida%200x3>

***

jadx로 해당 .apk를 까주면 다음과 같은 코드가 어셈블리 된다. \
(정석적으로 MainActivity부터 들어가준다)

<figure><img src="https://blog.kakaocdn.net/dna/u5KiS/dJMcajgQAtQ/AAAAAAAAAAAAAAAAAAAAAOoRiq96gOwNJN8gt_b9zU7JX8HCY4MYMPP66pXpL1CU/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=%2BI0IxZCMH3%2FORekFVZ4asi2FcNM%3D" alt="" height="892" width="1426"><figcaption></figcaption></figure>

checker 클래스에서 받은 code의 값이 512와 같으면 You Won!!을 출력하는 분기문을 타게 된다.&#x20;

<figure><img src="https://blog.kakaocdn.net/dna/bmhlMX/dJMcagYLM0j/AAAAAAAAAAAAAAAAAAAAAC7Nsf9kaIGvvPn-I0-OJXUHDx9DVfhArjAMYDQBu-Vo/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=P2qjY0ZIFwmTevLpmdLlr6H3jno%3D" alt="" height="295" width="445"><figcaption></figcaption></figure>

checker 내부를 보면 increase()안에서 code의 연산이 2씩 더해지면서 이루어지고 있다. 그러나 이 increase()는 어디서도 호출되지 않는다.

다시 MainActivity로 돌아간다.&#x20;

```
btn.setOnClickListener(new View.OnClickListener() { // from class: com.ad2001.frida0x3.MainActivity.1
    @Override // android.view.View.OnClickListener
    public void onClick(View v) {
        if (Checker.code == 512) {
            ...
            ...
            ...
        }
        ...
    }
});
```

아까 함수 형태가 이랬다. 주어진 모바일 앱의 버튼을 클릭하면 code 변수의 값이 512인지 검사한다. \
만약 이 조건이 참이라면 "You Won!!"이란 메시지의 Toast를 표시하고 플래그를 복호화한다. 그리고 그 결과를 TextView에 설정한다. \
거짓이면 "Try Again"을 가진 Toast만 표시된다. \
이 문제를 해결하기 위해선 Frida로 code 변수를 512로 변경하거나, increase() 메서드를 Frida로 256번 호출하는 방법이 있겠다. (2\*256 = 512임을 기억한다.)

**Code 변수의 값 변경하기**&#x20;

플래그를 얻기 위해 code 변수를 512로 변경한다.

```
public class Checker {
    static int code = 0;

    public static void increase() {
        code += 2;
    }
}
```

&#x20;\
그리고 앞서 소개했던 Frida 스크립트 템플릿을 가져와본다.&#x20;

```
Java.perform(function (){
    var <class_reference> = Java.use("<package_name>.<class>");
    <class_reference>.<variable>.value = <value>;
})
```

이제 code 변수의 값을 변경해본다.&#x20;

* 패키지 이름: com.ad2001.frida0x3
* 클래스 이름: Checker

Frida를 사용해 이 클래스의 변수 code 값을 직접 512로 바꾸면 된다.

```
Java.perform(function (){
    var a= Java.use("com.ad2001.frida0x3.Checker");
    a.code.value = 512;
})
```

&#x20;\
&#x20;

```
PS C:\Users\after\Downloads> adb install Challenge_0x3.apk
Performing Streamed Install
Success
```

우선 adb에 해당 앱을 깔아준다.&#x20;

```
PS C:\Users\after\Downloads> frida -U -f com.ad2001.frida0x3
     ____
    / _  |   Frida 17.5.1 - A world-class dynamic instrumentation toolkit
   | (_| |
    > _  |   Commands:
   /_/ |_|       help      -> Displays the help system
   . . . .       object?   -> Display information about 'object'
   . . . .       exit/quit -> Exit
   . . . .
   . . . .   More info at https://frida.re/docs/home/
   . . . .
   . . . .   Connected to Android Emulator 5554 (id=emulator-5554)
Spawned `com.ad2001.frida0x3`. Resuming main thread!
[Android Emulator 5554::com.ad2001.frida0x3 ]-> Java.perform(function() { var a=Java.use("com.ad2001.frida0x3.Checker")
; a.code.value=512; })
```

<figure><img src="https://blog.kakaocdn.net/dna/bR99jA/dJMcajuoWBZ/AAAAAAAAAAAAAAAAAAAAANTFy2p5RgMaITZ1L_Ez4T6h4yL6RIkikMFeRF4jFSqs/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=Ex2hw93kLBYrnLvFYytLrS7H79c%3D" alt="" height="580" width="281"><figcaption></figcaption></figure>

후킹이 된 것을 확인할 수 있다.&#x20;

**increase() 메서드를 반복 호출하는 법**

increase() 메서드는 호출될 때마다 code에 2씩 더해준다. 반복문을 사용해 256번 호출해준다.&#x20;

```
Java.perform(function(){
	var a=Java.use("com.ad2001.frida0x3.Checker");
    for(var i=0;i<=256,i++){
    	console.log("Calling increase Method" + i + " times");
        a.increase();
    }
});
```

<figure><img src="https://blog.kakaocdn.net/dna/xFABS/dJMcabwn5zC/AAAAAAAAAAAAAAAAAAAAAF_Z0_W5bRTKOOCsLB8UmssFdy7FF_sRlD3TpBsClcFz/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=u0jxc2t69Vgqt3Zi%2ByP%2FgMOhpoE%3D" alt="" height="637" width="672"><figcaption></figcaption></figure>

위와 같이 로그가 찍히는 것을 볼 수 있고,&#x20;

<figure><img src="https://blog.kakaocdn.net/dna/4lz67/dJMcaaEheHa/AAAAAAAAAAAAAAAAAAAAAOt5JRu4eo7PhUm-pYvBj1MA24KDvcLEOP0uj8K3iLkd/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=5J4674VGuO3svyt4PLfRRRtQYfY%3D" alt="" height="572" width="287"><figcaption></figcaption></figure>

플래그가 출력된다!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cooku222.kr/security/mobile/frida-lab/frida-labs-0x3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
