|
| 1 | +const parse = require("node-html-parser").parse; |
| 2 | + |
| 3 | +function extractJSFromHTA(s) { |
| 4 | + const root = parse("" + s); |
| 5 | + items = root.querySelectorAll('script'); |
| 6 | + r = ""; |
| 7 | + var chunkNum = 0; |
| 8 | + for (let i1 = 0; i1 < items.length; ++i1) { |
| 9 | + item = items[i1]; |
| 10 | + for (let i2 = 0; i2 < item.childNodes.length; ++i2) { |
| 11 | + chunkNum += 1; |
| 12 | + child = item.childNodes[i2] |
| 13 | + attrs = ("" + child.parentNode.rawAttrs).toLowerCase(); |
| 14 | + if (!attrs.includes("vbscript")) { |
| 15 | + r += "// Chunk #" + chunkNum + "\n" + child._rawText + "\n\n"; |
| 16 | + } |
| 17 | + } |
| 18 | + } |
| 19 | + return r; |
| 20 | +} |
| 21 | + |
| 22 | +var location = { |
| 23 | + |
| 24 | + /* |
| 25 | + Location.ancestorOrigins |
| 26 | + Is a static DOMStringList containing, in reverse order, the origins |
| 27 | + of all ancestor browsing contexts of the document associated with |
| 28 | + the given Location object. |
| 29 | + */ |
| 30 | + ancestorOrigins: '', |
| 31 | + |
| 32 | + /* |
| 33 | + Location.href |
| 34 | + Is a stringifier that returns a USVString containing the entire |
| 35 | + URL. If changed, the associated document navigates to the new |
| 36 | + page. It can be set from a different origin than the associated |
| 37 | + document. |
| 38 | + */ |
| 39 | + href: 'http://mylegitdomain.com:2112/and/i/have/a/path.php', |
| 40 | + |
| 41 | + /* |
| 42 | + Location.protocol |
| 43 | + Is a USVString containing the protocol scheme of the URL, including |
| 44 | + the final ':'. |
| 45 | + */ |
| 46 | + protocol: 'http:', |
| 47 | + |
| 48 | + /* |
| 49 | + Location.host |
| 50 | + Is a USVString containing the host, that is the hostname, a ':', and |
| 51 | + the port of the URL. |
| 52 | + */ |
| 53 | + host: 'mylegitdomain.com:2112', |
| 54 | + |
| 55 | + /* |
| 56 | + Location.hostname |
| 57 | + Is a USVString containing the domain of the URL. |
| 58 | + */ |
| 59 | + hostname: 'mylegitdomain.com', |
| 60 | + |
| 61 | + /* |
| 62 | + Location.port |
| 63 | + Is a USVString containing the port number of the URL. |
| 64 | + */ |
| 65 | + port: '2112', |
| 66 | + |
| 67 | + /* |
| 68 | + Location.pathname |
| 69 | + Is a USVString containing an initial '/' followed by the path of the URL. |
| 70 | + */ |
| 71 | + pathname: '/and/i/have/a/path.php', |
| 72 | + |
| 73 | + /* |
| 74 | + Location.search |
| 75 | + Is a USVString containing a '?' followed by the parameters or |
| 76 | + "querystring" of the URL. Modern browsers provide URLSearchParams |
| 77 | + and URL.searchParams to make it easy to parse out the parameters |
| 78 | + from the querystring. |
| 79 | + */ |
| 80 | + search: '', |
| 81 | + |
| 82 | + /* |
| 83 | + Location.hash |
| 84 | + Is a USVString containing a '#' followed by the fragment identifier |
| 85 | + of the URL. |
| 86 | + */ |
| 87 | + hash: '', |
| 88 | + |
| 89 | + /* |
| 90 | + Location.origin Read only |
| 91 | + Returns a USVString containing the canonical form of the origin of |
| 92 | + the specific location. |
| 93 | + */ |
| 94 | + origin: 'http://mylegitdomain.com:2112', |
| 95 | + |
| 96 | + replace: function (url) { |
| 97 | + logIOC('Window Location', {url}, "The script changed the window location URL."); |
| 98 | + logUrl('Window Location', {url}); |
| 99 | + }, |
| 100 | + |
| 101 | + // The location.reload() method reloads the current URL, like the Refresh button. |
| 102 | + reload: function() {}, |
| 103 | +}; |
| 104 | + |
| 105 | +var window = { |
| 106 | + eval: function(cmd) { eval(cmd); }, |
| 107 | + resizeTo: function(a,b){}, |
| 108 | + moveTo: function(a,b){}, |
| 109 | + close: function(){}, |
| 110 | + atob: function(s){ |
| 111 | + return new Buffer(s, 'base64').toString('ascii'); |
| 112 | + }, |
| 113 | + setTimeout: function(f, i) {}, |
| 114 | + location: location, |
| 115 | + localStorage: { |
| 116 | + // Users and session to distinguish and generate statistics about website traffic. |
| 117 | + "___utma" : undefined, |
| 118 | + // Users and session to distinguish and generate statistics about website traffic. |
| 119 | + "__utma" : undefined, |
| 120 | + // Determine new sessions and visits and generate statistics about website traffic. |
| 121 | + "__utmb" : undefined, |
| 122 | + // Determine new sessions and visits and generate statistics about website traffic. |
| 123 | + "__utmc" : undefined, |
| 124 | + // Process user requests and generate statistics about the website traffic. |
| 125 | + "__utmt" : undefined, |
| 126 | + // Store customized variable data at visitor level and generate statistics about the website traffic. |
| 127 | + "__utmv" : undefined, |
| 128 | + // To record the traffic source or campaign how users ended up on the website. |
| 129 | + "__utmz" : undefined, |
| 130 | + }, |
| 131 | +}; |
| 132 | + |
| 133 | +var document = { |
| 134 | + documentMode: 8, // Fake running in IE8 |
| 135 | + referrer: 'https://bing.com/', |
| 136 | + location: location, |
| 137 | + //parentNode: window.document.parentNode, |
| 138 | + getElementById : function(id) { |
| 139 | + |
| 140 | + var char_codes_to_string = function (str) { |
| 141 | + var codes = "" |
| 142 | + for (var i = 0; i < str.length; i++) { |
| 143 | + codes += String.fromCharCode(str[i]) |
| 144 | + } |
| 145 | + return codes |
| 146 | + } |
| 147 | + |
| 148 | + /* IDS_AND_DATA */ |
| 149 | + |
| 150 | + for (var i = 0; i < ids.length; i++) { |
| 151 | + if (char_codes_to_string(ids[i]) == id) { |
| 152 | + return { |
| 153 | + innerHTML: char_codes_to_string(data[i]) |
| 154 | + } |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + // got nothing to return |
| 159 | + return { |
| 160 | + innerHTML: "" |
| 161 | + } |
| 162 | + }, |
| 163 | + write: function (content) { |
| 164 | + logIOC('DOM Write', {content}, 'The script wrote to the DOM') |
| 165 | + eval.apply(null, [extractJSFromHTA(content)]); |
| 166 | + }, |
| 167 | + appendChild: function(node) { |
| 168 | + logIOC('DOM Append', {node}, "The script appended an HTML node to the DOM") |
| 169 | + eval(extractJSFromHTA(node)); |
| 170 | + }, |
| 171 | + insertBefore: function(node) { |
| 172 | + logIOC('DOM Insert', {node}, "The script inserted an HTML node on the DOM") |
| 173 | + eval(extractJSFromHTA(node)); |
| 174 | + }, |
| 175 | + getElementsByTagName: function(tag) { |
| 176 | + var func = function(item) { |
| 177 | + logIOC('DOM Append', {item}, "The script added a HTML node to the DOM"); |
| 178 | + return ""; |
| 179 | + }; |
| 180 | + |
| 181 | + // Return a dict that maps every tag name to the same fake element. |
| 182 | + fake_dict = {}; |
| 183 | + fake_dict = new Proxy(fake_dict, { |
| 184 | + get(target, phrase) { // intercept reading a property from dictionary |
| 185 | + return { |
| 186 | + "appendChild" : func, |
| 187 | + "insertBefore" : func, |
| 188 | + "parentNode" : { |
| 189 | + "appendChild" : func, |
| 190 | + "insertBefore" : func, |
| 191 | + }, |
| 192 | + }; |
| 193 | + } |
| 194 | + }); |
| 195 | + return fake_dict; |
| 196 | + }, |
| 197 | + createElement: function(tag) { |
| 198 | + var fake_elem = { |
| 199 | + set src(url) { |
| 200 | + logIOC('Remote Script', {url}, "The script set a remote script source."); |
| 201 | + logUrl('Remote Script', {url}); |
| 202 | + }, |
| 203 | + log: [] |
| 204 | + }; |
| 205 | + return fake_elem; |
| 206 | + }, |
| 207 | + createTextNode: function(text) { |
| 208 | + //return window.document.createTextNode(text) |
| 209 | + }, |
| 210 | + addEventListener: function(tag, func) {} |
| 211 | +}; |
| 212 | + |
| 213 | +function atob(s) { |
| 214 | + var b = new Buffer(s, 'base64'); |
| 215 | + return b.toString(); |
| 216 | +}; |
| 217 | + |
| 218 | +class _WidgetInfo { |
| 219 | + constructor(a1, a2, a3, a4, a5) {} |
| 220 | +} |
| 221 | + |
| 222 | +var _WidgetManager = { |
| 223 | + _Init: function(a1, a2, a3) {}, |
| 224 | + _SetDataContext: function(a1) {}, |
| 225 | + _RegisterWidget: function(a1, a2) {} |
| 226 | +} |
| 227 | + |
| 228 | +var navigator = { |
| 229 | + userAgent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Tablet PC 2.0; InfoPath.3)' |
| 230 | +} |
| 231 | + |
| 232 | +// We are acting like cscript when emulating. JS in cscript does not |
| 233 | +// implement Array.reduce(). |
| 234 | +Array.prototype.reduce = function(a, b) { |
| 235 | + throw "CScript JScript has no Array.reduce() method." |
| 236 | +}; |
0 commit comments