Skip to content

Commit 0ba4288

Browse files
committed
intentional exercise
1 parent 5bfabf0 commit 0ba4288

12 files changed

+183
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
| Moderate (5 / flag) | [TempImage][4] | Web | 2 / 2 |
2323
| Easy (2 / flag) | [H1 Thermostat][11] | Android | 2 / 2 |
2424
| Expert (13 / flag) | [Model E1337 v2 - Hardened Rolling Code Lock][14] | Math | 0 / 1 |
25-
| Moderate (3 / flag) | [Intentional Exercise][15] | Android | 0 / 1 |
25+
| Moderate (3 / flag) | [Intentional Exercise][15] | Android | 1 / 1 |
2626
| Moderate (4 / flag) | [Hello World!][16] | Native | 0 / 1 |
2727
| Expert (9 / flag) | [Rend Asunder][17] | Native | 0 / 3 |
2828

intentional_exercise/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Intentional Exercise
2+
3+
## [Flag0](./flag0) -- Found
4+
5+
- Check the manifest
6+
- Is the link really broken?
7+
- Launching from another app might help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.hacker101.level13;
2+
3+
import android.net.Uri;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.webkit.WebView;
7+
import android.webkit.WebViewClient;
8+
import java.math.BigInteger;
9+
import java.nio.charset.StandardCharsets;
10+
import java.security.MessageDigest;
11+
import java.security.NoSuchAlgorithmException;
12+
13+
public class MainActivity extends AppCompatActivity {
14+
protected void onCreate(Bundle paramBundle) {
15+
super.onCreate(paramBundle);
16+
setContentView(2131296284);
17+
WebView webView = (WebView)findViewById(2131165328);
18+
webView.setWebViewClient(new WebViewClient());
19+
Uri uri = getIntent().getData();
20+
str1 = "http://127.0.0.1/xxxxxxxxxx/appRoot";
21+
String str3 = "";
22+
if (uri != null) {
23+
str3 = uri.toString().substring(28);
24+
StringBuilder stringBuilder = new StringBuilder();
25+
stringBuilder.append("http://127.0.0.1/xxxxxxxxxx/appRoot");
26+
stringBuilder.append(str3);
27+
str1 = stringBuilder.toString();
28+
}
29+
String str2 = str1;
30+
if (!str1.contains("?")) {
31+
StringBuilder stringBuilder = new StringBuilder();
32+
stringBuilder.append(str1);
33+
stringBuilder.append("?");
34+
str2 = stringBuilder.toString();
35+
}
36+
try {
37+
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
38+
messageDigest.update("s00p3rs3cr3tk3y".getBytes(StandardCharsets.UTF_8));
39+
messageDigest.update(str3.getBytes(StandardCharsets.UTF_8));
40+
byte[] arrayOfByte = messageDigest.digest();
41+
BigInteger bigInteger = new BigInteger();
42+
this(1, arrayOfByte);
43+
String str = String.format("%064x", new Object[] { bigInteger });
44+
StringBuilder stringBuilder = new StringBuilder();
45+
this();
46+
stringBuilder.append(str2);
47+
stringBuilder.append("&hash=");
48+
stringBuilder.append(str);
49+
webView.loadUrl(stringBuilder.toString());
50+
} catch (NoSuchAlgorithmException str1) {
51+
str1.printStackTrace();
52+
}
53+
}
54+
}

intentional_exercise/flag0/README.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Intentional Exercise - FLAG0
2+
3+
## 0x00 App Home
4+
5+
On app load, a request is sening to server and got an flag link.
6+
7+
![](./imgs/home.jpg)
8+
9+
However, the result shows invalid request
10+
11+
![](./imgs/invalid.jpg)
12+
13+
## 0x01 Mutate Request
14+
15+
It is a practice to modify all the HTTP parameters you can reach.
16+
17+
It seems always send the same link no matter what parameter I send in request.
18+
19+
![](./imgs/request.jpg)
20+
21+
But the second request needs more data.
22+
23+
![](./imgs/flagbearer.jpg)
24+
25+
After adding the parameter **hash**, it shows a diffeerent response.
26+
27+
![](./imgs/invalid_hash.jpg)
28+
29+
## 0x02 Check Source
30+
31+
As we have the **apk** file, we may check inside of it.
32+
33+
### Dex to Jar
34+
35+
Use [dex2jar][1] to convert to **jar**.
36+
37+
```batch
38+
d2j-dex2jar.bat -f ./level13.apk
39+
```
40+
41+
So we got **level13-dex2jar.jar** now.
42+
43+
### Decompile
44+
45+
Use [jd-gui][1] to chek inside of the **jar**.
46+
47+
![](./imgs/source.jpg)
48+
49+
## 0x03 Code Review
50+
51+
The full source can be found at [MainActivity.java][3]
52+
53+
```java
54+
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
55+
messageDigest.update("s00p3rs3cr3tk3y".getBytes(StandardCharsets.UTF_8));
56+
messageDigest.update(str3.getBytes(StandardCharsets.UTF_8));
57+
byte[] arrayOfByte = messageDigest.digest();
58+
```
59+
60+
The request hash is generated with the secret key **s00p3rs3cr3tk3y** and the message payload **str3** with **SHA-256**
61+
62+
However, the first request [hash][4] is just the secret key without any payload.
63+
64+
http://127.0.0.1/xxxxxxxxxx/appRoot?&hash=61f4518d844a9bd27bb971e55a23cd6cf3a9f5ef7f46285461cf6cf135918a1a
65+
66+
```
67+
SHA-256(s00p3rs3cr3tk3y) = 61f4518d844a9bd27bb971e55a23cd6cf3a9f5ef7f46285461cf6cf135918a1a
68+
```
69+
70+
## 0x04 Get Hash
71+
72+
There is another piece of code shows the hint.
73+
74+
```java
75+
Uri uri = getIntent().getData();
76+
str3 = uri.toString().substring(28);
77+
```
78+
79+
and
80+
81+
```xml
82+
<data
83+
android:scheme="http"
84+
android:host="level13.hacker101.com"
85+
/>
86+
```
87+
88+
So the payload string after the index of 28 should be
89+
90+
```java
91+
"http://level13.hacker101.com".substring(28);
92+
```
93+
94+
| uri | payload |
95+
| ------------------ | ----------- |
96+
| /appRoot | null |
97+
| /appRoot/flagBeare | /flagBearer |
98+
99+
So we need to encrypt **/flagBearer** with secret key **s00p3rs3cr3tk3y** for this hash.
100+
101+
Try use this online [tool][5].
102+
103+
![](./imgs/encrypt.jpg)
104+
105+
```
106+
SHA-256(s00p3rs3cr3tk3y/flagBearer) = 8743a18df6861ced0b7d472b34278dc29abba81b3fa4cf836013426d6256bd5e
107+
```
108+
109+
## 0x05 FLAG
110+
111+
Create a new get request with the new generated hash. The server will send back FLAG.
112+
113+
http://127.0.0.1/xxxxxxxxxx/appRoot/flagBearer?&hash=8743a18df6861ced0b7d472b34278dc29abba81b3fa4cf836013426d6256bd5e
114+
115+
![](./imgs/flag.jpg)
116+
117+
[1]: https://github.com/pxb1988/dex2jar
118+
[2]: https://github.com/java-decompiler/jd-gui
119+
[3]: ./MainActivity.java
120+
[4]: https://www.cmd5.com/hash.aspx?s=s00p3rs3cr3tk3y
121+
[4]: https://www.cmd5.com/hash.aspx?s=s00p3rs3cr3tk3y/flagBearer
8.04 KB
Loading
53 KB
Loading
47.4 KB
Loading
5.12 KB
Loading
3.07 KB
Loading
47.9 KB
Loading
47.2 KB
Loading
117 KB
Loading

0 commit comments

Comments
 (0)