Skip to content

Commit 4f26cca

Browse files
committed
RaziCTF2020
1 parent 9f97d1c commit 4f26cca

File tree

22 files changed

+261
-2
lines changed

22 files changed

+261
-2
lines changed

Diff for: README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ Here we upload:
99
- Helpful tools and sitess
1010

1111

12-
##### Design by our CTF Team, [0xDED5EC](https://ctftime.org/team/50270).
12+
##### Design by our CTF Team, [TernaryBits](https://ctftime.org/team/50270).
1313

1414
## List of challenges
15+
### Android
16+
17+
- [razictf2020-chasing-a-lock](./android/razictf2020-chasing-a-lock/)
18+
- [razictf2020-ctf-coin](./android/razictf2020-ctf-coin/)
19+
- [razictf2020-friends](./android/razictf2020-friends/)
20+
1521
### Cryptograpy:
1622

1723
- [Tamuctf-crypto3: :)](./cryptography/tamuctf_\:\)/tamuctf-crypto3.md)
@@ -32,4 +38,4 @@ Here we upload:
3238
### Web:
3339

3440
- [UTCTF-web1: epic admin pwn](./web/epic-admin-pwn/WRITEUP.md)
35-
- [UTCTF-web3: Shrek Fans Only](./web/shrek-fans-only/WRITEUP.md)
41+
- [UTCTF-web3: Shrek Fans Only](./web/shrek-fans-only/WRITEUP.md)

Diff for: android/razictf2020-chasing-a-lock/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Challenge: Chasing a Lock
2+
score: 858
3+
difficulty: easy
4+
5+
## Description
6+
[app-release.apk](./app-release.apk)
7+
8+
as locks are so popular many will chase them but why? maybe a flag :)
9+
10+
### Write-up
11+
[link](./WRITEUP.md)
12+

Diff for: android/razictf2020-chasing-a-lock/WRITEUP.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Write-up: Chasing a Lock
2+
![badge](https://img.shields.io/badge/Post%20CTF-Writeup-success)
3+
4+
## Description
5+
6+
### My Story
7+
First I executed the app and this is it:
8+
9+
![chasing a lock](./challenge.png)
10+
11+
Each time you touch the lock, the counter at the bottom of the page will decrease by one; while the lock changes its position randomly every second.
12+
13+
me: "So I should make the counter zero!" :D
14+
15+
I got the point and opened JADX and found the source code without any obfuscation. This is the source code of MainActivity:
16+
```
17+
package com.example.razictf_2;
18+
19+
import android.os.Bundle;
20+
import android.util.DisplayMetrics;
21+
import android.view.View;
22+
import android.view.View.OnClickListener;
23+
import android.widget.ImageButton;
24+
import android.widget.TextView;
25+
import androidx.appcompat.app.AppCompatActivity;
26+
import java.util.Random;
27+
import java.util.Timer;
28+
import java.util.TimerTask;
29+
30+
public class MainActivity extends AppCompatActivity {
31+
public void onCreate(Bundle bundle) {
32+
super.onCreate(bundle);
33+
setContentView((int) R.layout.activity_main);
34+
final ImageButton imageButton = (ImageButton) findViewById(R.id.my_button);
35+
final DisplayMetrics displayMetrics = new DisplayMetrics();
36+
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
37+
new Timer().schedule(new TimerTask() {
38+
public void run() {
39+
MainActivity.this.runOnUiThread(new Runnable() {
40+
public void run() {
41+
Random random = new Random();
42+
float nextFloat = random.nextFloat() * ((float) displayMetrics.widthPixels);
43+
float nextFloat2 = random.nextFloat() * ((float) displayMetrics.heightPixels);
44+
new Timer();
45+
imageButton.animate().x(nextFloat).y(nextFloat2).setDuration(0).start();
46+
}
47+
});
48+
}
49+
}, 0, 1000);
50+
imageButton.setOnClickListener(new OnClickListener() {
51+
public void onClick(View view) {
52+
TextView textView = (TextView) MainActivity.this.findViewById(R.id.Num);
53+
int parseInt = Integer.parseInt(textView.getText().toString());
54+
if (parseInt == 0 || parseInt < 0) {
55+
textView.setText("0");
56+
return;
57+
}
58+
int i = parseInt - 1;
59+
String run = new switcher().run(i);
60+
if (run != null) {
61+
((TextView) MainActivity.this.findViewById(R.id.Flag)).setText(run);
62+
}
63+
textView.setText(String.valueOf(i));
64+
}
65+
});
66+
}
67+
}
68+
```
69+
70+
And this is the interesting point:
71+
```
72+
String run = new switcher().run(i);
73+
```
74+
75+
It seems the magic part is inside the `switcher` class. This is the source code:
76+
```
77+
package com.example.razictf_2;
78+
79+
public class switcher {
80+
public String run(int i) {
81+
if (i != 0) {
82+
return null;
83+
}
84+
a1 a1Var = new a1();
85+
StringBuilder sb = new StringBuilder();
86+
sb.append(" ");
87+
sb.append(a1Var.run(i));
88+
String sb2 = sb.toString();
89+
a2 a2Var = new a2();
90+
System.out.println(a2Var.run(i));
91+
StringBuilder sb3 = new StringBuilder();
92+
sb3.append(sb2);
93+
sb3.append(a2Var.run(i));
94+
String sb4 = sb3.toString();
95+
a3 a3Var = new a3();
96+
StringBuilder sb5 = new StringBuilder();
97+
sb5.append(sb4);
98+
sb5.append(a3Var.run(i));
99+
String sb6 = sb5.toString();
100+
a4 a4Var = new a4();
101+
StringBuilder sb7 = new StringBuilder();
102+
sb7.append(sb6);
103+
sb7.append(a4Var.run(i));
104+
String sb8 = sb7.toString();
105+
a5 a5Var = new a5();
106+
StringBuilder sb9 = new StringBuilder();
107+
sb9.append(sb8);
108+
sb9.append(a5Var.run(i));
109+
return sb9.toString();
110+
}
111+
}
112+
```
113+
114+
### Exploit Time
115+
So the only thing I need to do is hooking the `run` method and rewrite the value of `i` argument to zero. It's really easy using Frida.
116+
I wrote [loader.py](./loader.py) and [script.js](./script.js).
117+
118+
### Flag
119+
And this is the result:
120+
![flag](./flag.png)

Diff for: android/razictf2020-chasing-a-lock/app-release.apk

Whitespace-only changes.

Diff for: android/razictf2020-chasing-a-lock/challenge.png

30.2 KB
Loading

Diff for: android/razictf2020-chasing-a-lock/flag.png

36 KB
Loading

Diff for: android/razictf2020-chasing-a-lock/loader.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import time
2+
import frida
3+
4+
device = frida.get_usb_device()
5+
pid = device.spawn(["com.example.razictf_2"])
6+
device.resume(pid)
7+
time.sleep(1) # Without it Java.perform silently fails
8+
session = device.attach(pid)
9+
with open("script.js") as f:
10+
script = session.create_script(f.read())
11+
script.load()
12+
13+
# prevent the python script from terminating
14+
input()

Diff for: android/razictf2020-chasing-a-lock/script.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
console.log("Script loaded successfully ");
2+
Java.perform(function x() { //Silently fails without the sleep from the python code
3+
console.log("Inside java perform function");
4+
//get a wrapper for our class
5+
var my_class1 = Java.use("com.example.razictf_2.switcher"); // freind page
6+
//replace the original implmenetation of the function `fun` with our custom function
7+
my_class1.run.implementation = function (i) {
8+
//print the original arguments
9+
console.log(": run(" + i + ")");
10+
//call the original implementation of `fun` with args (2,5)
11+
i = 0;
12+
var ret_value = this.run(i);
13+
return ret_value;
14+
}
15+
});

Diff for: android/razictf2020-ctf-coin/1.png

Loading

Diff for: android/razictf2020-ctf-coin/2.png

50.3 KB
Loading

Diff for: android/razictf2020-ctf-coin/3.png

45 KB
Loading

Diff for: android/razictf2020-ctf-coin/4.png

Loading

Diff for: android/razictf2020-ctf-coin/5.png

Loading

Diff for: android/razictf2020-ctf-coin/6.png

Loading

Diff for: android/razictf2020-ctf-coin/7.png

32.6 KB
Loading

Diff for: android/razictf2020-ctf-coin/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Challenge: Chasing a Lock
2+
difficulty: easy
3+
4+
## Description
5+
[ctf-coin.apk](./ctf-coin.apk)
6+
7+
Make your CTF Coins Unlimited (more than 1000000000000000)
8+
9+
### Write-up
10+
[link](./WRITEUP.md)
11+

Diff for: android/razictf2020-ctf-coin/WRITEUP.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Write-up: CTF Coin
2+
![badge](https://img.shields.io/badge/Post%20CTF-Writeup-success)
3+
4+
## Description
5+
There are some images in this directory of the app In-App Purchase (IAP) and ...
6+
7+
### My Story
8+
First I thought it should be a problem of app itself! so I dived deep inside the app. I used static analysis to understand what it is doing. but it was somehow confusing and complicated. so I tried another way; dynamic analysis. I started Burp and trying to monitor the traffic.
9+
10+
but there was a problem! This error was occurring repeatedly and I couldn't do the purchase while system proxy setting was set to my Burp IP! I had set the cert; so I didn't know the cause of the problem!
11+
```
12+
BurpSuite Error: failed to negotiate an SSL connection
13+
```
14+
I saw a new phrase I didn't know what is it; `SSL Pinning`. But I remembered a script from [codeshare.frida.re](https://codeshare.frida.re) named `Universal Android SSL Pinning Bypass with Frida`. So this is the solution to bypass this #&%^#@!
15+
16+
![SSL Pinning Bypassed](./7.png)
17+
18+
It took a lot of time to analyze statically and finding out the solution of `SSL Pinning` problem. But I learned a lot! :P
19+
20+
After bypassing SSL Pinning it was so easy to capture the traffic to the back-end server.
21+
22+
![SSL Pinning Bypassed](./6.png)
23+
24+
### Exploit Time
25+
Then I sent another value as `coins` parameter:
26+
27+
![SSL Pinning Bypassed](./5.png)
28+
29+
### Flag
30+
And this is the flag:
31+
32+
```
33+
RaziCTF{ZmRzdnNkRlNEcWUzQFFxZURXRUZEU1ZGU0RTNTVkc2Y1ZmV2c0RGcnEzNSRSI3J3ZnNlZnJ3IyQjJSNA}
34+
```

Diff for: android/razictf2020-ctf-coin/ctf-coin.apk

Whitespace-only changes.

Diff for: android/razictf2020-friends/1.png

Loading

Diff for: android/razictf2020-friends/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Challenge: Friends
2+
difficulty: easy
3+
4+
## Description
5+
[friends.apk](./friends.apk)
6+
7+
The flag is created by putting it together
8+
9+
### Write-up
10+
[link](./WRITEUP.md)
11+

Diff for: android/razictf2020-friends/WRITEUP.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Write-up: Friends
2+
![badge](https://img.shields.io/badge/Post%20CTF-Writeup-success)
3+
4+
## Description
5+
6+
### My Story
7+
I just started Burp and analyzed the traffic! this is the result:
8+
9+
![network traffic](./1.png)
10+
11+
There are some data that server respond, but the app doesn't show them; phone numbers.
12+
13+
I didn't know what should I do with these phone numbers to get the flag. This is the captured server response:
14+
```
15+
HTTP/1.1 200 OK
16+
Server: nginx/1.18.0 (Ubuntu)
17+
Content-Type: application/json
18+
Cache-Control: no-cache, private
19+
Date: Mon, 26 Oct 2020 16:17:47 GMT
20+
X-RateLimit-Limit: 60
21+
X-RateLimit-Remaining: 57
22+
Access-Control-Allow-Origin: *
23+
Connection: close
24+
Content-Length: 1388
25+
26+
[{"id":1,"name":"Bugs Bunny","avatar":"bugs_bunny.jpg","email":"[email protected]","address":"4617 Goodwin Avenue","gender":"male","age":"22","phone":"36213893021"},{"id":2,"name":"Mickey Mouse","avatar":"mickey_mouse.jpg","email":"[email protected]","address":"3844 Stiles Street","gender":"male","age":"28","phone":"12369532255"},{"id":4,"name":"Bart Simpson","avatar":"bart_simpson.jpg","email":"[email protected]","address":"2418 Loving Acres Road","gender":"male","age":"35","phone":"55634559910"},{"id":3,"name":"Popeye","avatar":"popeye.jpg","email":"[email protected]","address":"New Jersey popeye Street","gender":"male","age":"43","phone":"22361255893"},{"id":5,"name":"Patrick Star","avatar":"patrick_star.jpg","email":"[email protected]","address":"Richmond 2136 Queens Lane","gender":"male","age":"18","phone":"41223365236"},{"id":6,"name":"Homer Simpson","avatar":"homer_simpson.jpg","email":"[email protected]","address":"Timber Oak Drive","gender":"male","age":"47","phone":"99632531930"},{"id":7,"name":"Olive Oyl","avatar":"olive_oyl.jpg","email":"[email protected]","address":"Ocala Rhapsody Street","gender":"female","age":"52","phone":"89633366552"},{"id":8,"name":"Sylvester","avatar":"sylvester.jpg","email":"[email protected]","address":"Tigard 2285 Kincheloe Road","gender":"male","age":"31","phone":"77632351752"}]
27+
```
28+
29+
### Exploit Time
30+
...
31+
32+
### Flag
33+
It's ridiculous. just putting the numbers together:
34+
```
35+
RaziCTF{3621389302112369532255556345599102236125589341223365236996325319308963336655277632351752}
36+
```

Diff for: android/razictf2020-friends/friends.apk

Whitespace-only changes.

0 commit comments

Comments
 (0)