|
| 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 | + |
| 8 | + |
| 9 | +However, the result shows invalid request |
| 10 | + |
| 11 | + |
| 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 | + |
| 20 | + |
| 21 | +But the second request needs more data. |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +After adding the parameter **hash**, it shows a diffeerent response. |
| 26 | + |
| 27 | + |
| 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 | + |
| 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 | + |
| 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 | + |
| 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 |
0 commit comments