all.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import frida from "frida"
  2. import fs from "fs"
  3. import url from "url"
  4. import path from "path"
  5. import util from "util"
  6. import Vorpal from "vorpal"
  7. import { spawn, execSync } from "child_process"
  8. const filePath = url.fileURLToPath(import.meta.url)
  9. const __dirname = path.dirname(filePath)
  10. function pushFile(file, dest, force = false) {
  11. const fileName = path.basename(file)
  12. const srcPath = path.resolve(__dirname, file)
  13. const destPath = path.resolve(dest, fileName)
  14. if (!force) {
  15. console.log(`Checking if ${destPath} exists`)
  16. try {
  17. if (
  18. execSync(`adb shell ls ${destPath}`)
  19. .toString()
  20. .includes("No such file or directory")
  21. ) {
  22. throw new Error("File not found")
  23. }
  24. console.log(`File ${fileName} already exists`)
  25. return
  26. } catch (e) {
  27. console.log(`File ${fileName} not found`)
  28. }
  29. }
  30. // execSync(`adb shell mkdir ${dest}`)
  31. console.log(`Pushing ${srcPath} to ${destPath}`)
  32. execSync(`adb push ${srcPath} ${destPath}`)
  33. console.log(`Push success: ${fileName}`)
  34. console.log(`set permission 777 to ${destPath}`)
  35. execSync(`adb shell chmod 777 ${destPath}`)
  36. console.log(`set permission success: ${fileName}`)
  37. }
  38. pushFile("../RcsHackTool.dex", "/sdcard/Download/")
  39. pushFile("../gson.dex", "/sdcard/Android/data/com.google.android.gms/")
  40. class Log {
  41. static TAG = ""
  42. static format(...msg) {
  43. let m = []
  44. for (let i = 0; i < msg.length; i++) {
  45. if (typeof msg[i] === "object") {
  46. if ("[object Object]" === msg[i].toString()) {
  47. m.push(util.inspect(msg[i]))
  48. }
  49. } else {
  50. m.push(msg[i])
  51. }
  52. }
  53. m = m.join(" ")
  54. return m
  55. }
  56. static i(...msg) {
  57. console.log(`\x1b[30m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  58. }
  59. static w(...msg) {
  60. console.log(`\x1b[33m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  61. }
  62. static e(...msg) {
  63. console.log(`\x1b[31m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  64. }
  65. static s(...msg) {
  66. console.log(`\x1b[32m${this.TAG} ${this.format(...msg)}\x1b[0m`)
  67. }
  68. }
  69. function replaceVars(source) {
  70. const vars = JSON.parse(
  71. fs.readFileSync(path.resolve(__dirname, "../vars.json")).toString()
  72. )
  73. return source
  74. .replace("{{mcc}}", vars.mcc)
  75. .replace("{{mnc}}", vars.mnc)
  76. .replace("{{simOperator}}", vars.simOperator)
  77. .replace("{{networkOperator}}", vars.networkOperator)
  78. .replace("{{simSerialNumber}}", vars.simSerialNumber)
  79. .replace("{{iccId}}", vars.iccId)
  80. .replace("{{number}}", vars.number)
  81. .replace("{{imei}}", vars.imei)
  82. .replace("{{imsi}}", vars.imsi)
  83. .replace("{{countryIso}}", vars.countryIso)
  84. .replace("{{subId}}", vars.subId)
  85. .replace("{{androidId}}", vars.androidId)
  86. .replace("{{serialNumber}}", vars.serialNumber)
  87. }
  88. function loadSource(filePath) {
  89. Log.s(`Loading ${filePath}`)
  90. return replaceVars(
  91. fs.readFileSync(path.resolve(__dirname, filePath)).toString()
  92. )
  93. }
  94. const source = loadSource("../scripts/spoof1.js")
  95. const source_gms = loadSource("../scripts/spoof_gms.js")
  96. const source_ssl = loadSource("../scripts/ssl_bypass.js")
  97. fs.writeFileSync("scripts/_spoof.js", source)
  98. fs.writeFileSync("scripts/_spoof_gms.js", source_gms)
  99. let device = null
  100. let tracers = []
  101. async function stop() {
  102. Log.i("[*] Stopping all tracers")
  103. for (const tracer of tracers) {
  104. Log.i("[*] Stopping", tracer.pid)
  105. tracer.session.detach()
  106. try {
  107. await device.kill(tracer.pid)
  108. } catch (error) {}
  109. }
  110. process.exit(1)
  111. }
  112. process.on("SIGTERM", stop)
  113. process.on("SIGINT", stop)
  114. async function main() {
  115. device = await frida.getUsbDevice()
  116. device.spawnAdded.connect(onSpawnAdded)
  117. Log.i("[*] Enabling spawn gating")
  118. await device.enableSpawnGating()
  119. Log.i("[*] Enabled spawn gating")
  120. // Log.i("[*] Spawning com.google.android.apps.messaging")
  121. // const pid = await device.spawn("com.google.android.apps.messaging")
  122. // Log.i("[*] Spawned com.google.android.apps.messaging: " + pid)
  123. // const tracer = await Tracer.open(pid)
  124. // tracers.push(tracer)
  125. }
  126. async function onSpawnAdded(spawn) {
  127. try {
  128. if (spawn.identifier.startsWith("com.google.android.apps.messaging")) {
  129. Log.i("[*] Tracing", spawn.pid, spawn.identifier)
  130. const tracer = await Tracer.open(
  131. spawn.pid,
  132. loadSource("../scripts/spoof1.js")
  133. )
  134. tracers.push(tracer)
  135. }
  136. if (spawn.identifier.startsWith("com.google.android.gms")) {
  137. Log.i("[*] Tracing", spawn.pid, spawn.identifier)
  138. const tracer = await Tracer.open(
  139. spawn.pid,
  140. loadSource("../scripts/spoof_gms.js")
  141. )
  142. tracers.push(tracer)
  143. } else {
  144. Log.i("[*] Resuming", spawn.pid, spawn.identifier)
  145. await device.resume(spawn.pid)
  146. }
  147. } catch (e) {
  148. Log.e(`err: ${e}`)
  149. }
  150. }
  151. class Tracer {
  152. static async open(pid, source) {
  153. const tracer = new Tracer(pid, source)
  154. await tracer._initialize()
  155. return tracer
  156. }
  157. constructor(pid, source) {
  158. this.pid = pid
  159. this.source = source
  160. this.session = null
  161. this.script = null
  162. }
  163. async _initialize() {
  164. const session = await device.attach(this.pid)
  165. this.session = session
  166. session.detached.connect(this._onSessionDetached.bind(this))
  167. const script = await session.createScript(this.source)
  168. this.script = script
  169. script.message.connect(this._onScriptMessage.bind(this))
  170. await script.load()
  171. // const script_ssl = await session.createScript(source_ssl)
  172. // await script_ssl.load()
  173. try {
  174. await device.resume(this.pid)
  175. } catch (e) {
  176. Log.e(e)
  177. }
  178. }
  179. _onSessionDetached(reason) {
  180. Log.w(`[PID ${this.pid}] onSessionDetached(reason='${reason}')`)
  181. const i = tracers.findIndex(tracer => tracer.pid === this.pid)
  182. if (i !== -1) {
  183. tracers.splice(i, 1)
  184. }
  185. }
  186. _onScriptMessage(message, data) {
  187. if (message.type === "error") {
  188. Log.e(
  189. `[PID ${this.pid}] onScriptMessage()`,
  190. message,
  191. data ? JSON.stringify(data) : ""
  192. )
  193. } else {
  194. Log.i(
  195. `[PID ${this.pid}] onScriptMessage()`,
  196. message,
  197. data ? JSON.stringify(data) : ""
  198. )
  199. }
  200. }
  201. }
  202. main()
  203. const vorpal = new Vorpal()
  204. vorpal.sigint(function () {
  205. stop()
  206. })
  207. vorpal.command("clear [app]").action(function (args, callback) {
  208. try {
  209. const app = args.app
  210. if ("sms" === app) {
  211. execSync("adb shell pm clear com.google.android.apps.messaging")
  212. } else if ("gms" === app) {
  213. execSync("adb shell pm clear com.google.android.gms")
  214. pushFile(
  215. "../gson.dex",
  216. "/sdcard/Android/data/com.google.android.gms/"
  217. )
  218. } else if ("gsf") {
  219. execSync("adb shell pm clear com.google.android.gsf")
  220. } else if ("all" === app) {
  221. execSync("adb shell pm clear com.google.android.apps.messaging")
  222. execSync("adb shell pm clear com.google.android.gms")
  223. pushFile(
  224. "../gson.dex",
  225. "/sdcard/Android/data/com.google.android.gms/"
  226. )
  227. }
  228. } catch (error) {
  229. Log.e(error)
  230. }
  231. callback()
  232. })
  233. vorpal.command("stop").action(function (args, callback) {
  234. try {
  235. execSync("adb shell am force-stop com.google.android.apps.messaging")
  236. execSync("adb shell am force-stop com.google.android.gms")
  237. } catch (error) {
  238. Log.e(error)
  239. }
  240. callback()
  241. })
  242. vorpal.command("gen").action(function (args, callback) {
  243. execSync(`node ${path.resolve(__dirname, "../gen.js")}`)
  244. callback()
  245. })
  246. vorpal.delimiter("rcs$").show()