Skip to content

Commit bdca8ea

Browse files
Merge pull request #82 from kirk-sayre-work/master
1.19.20 Release
2 parents fa6b298 + 393e5ad commit bdca8ea

23 files changed

+1727
-4156
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ Box.js will emulate a Windows JScript environment, print a summary of the emulat
4646
4747
>If you wish to automate the analysis, you can use the return codes - documented in `integrations/README.md` - to distinguish between different types of errors.
4848
49-
## Analysis Fails Due to Missing 'document' Object
49+
## Analysis Fails Due to Missing 'document' Object or Other Objects/Functions
5050

5151
The box-js repository from git includes a `boilerplate.js` file. This file defines some stubbed versions of common browser objects such as document. Try rerunning your analysis with the `--prepended-code=DIR/boilerplate.js` option, where `DIR` is the directory of the cloned box-js repository. The `--prepended-code` option tells box-js to prepend the JavaScript in the given file to the sample being analyzed.
5252

53+
Note that you can copy boilerplate.js and add your own stubbed classes, objects, etc. as needed.
54+
5355
## Batch usage
5456

5557
While box.js is typically used on single files, it can also run batch analyses. You can simply pass a list of files or folders to analyse:
@@ -88,6 +90,8 @@ cat ./*.results/active_urls.json | sort | uniq
8890
--preprocess Preprocess the original source code (makes reverse engineering easier, but takes
8991
a few seconds)
9092
--prepended-code Prepend the JavaScript in the given file to the sample prior to sandboxing
93+
--fake-script-engine The script engine to report in WScript.FullName and WScript.Name (ex.
94+
'cscript.exe' or 'wscript.exe'). Default is wscript.exe.
9195
--unsafe-preprocess More aggressive preprocessing. Often results in better code, but can break on
9296
some edge cases (eg. redefining prototypes)
9397
--no-kill Do not kill the application when runtime errors occur
@@ -114,6 +118,8 @@ cat ./*.results/active_urls.json | sort | uniq
114118
--dangerous-vm Use the `vm` module, rather than `vm2`. This sandbox can be broken, so **don't
115119
use this** unless you're 100% sure of what you're doing. Helps with debugging by
116120
giving correct stack traces.
121+
--rewrite-loops Rewrite some types of loops to make analysis faster
122+
--throttle-writes Throttle reporting and data tracking of file writes that write a LOT of data
117123
<!--END_FLAGS-->
118124

119125
# Analyzing the output

RELEASE_NOTES.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Version 1.19.20, 2/15/2023
2+
--------------------------
3+
4+
* Added anti-emulation loop rewriting functionality.
5+
* Added functionality for faking being run with cscript.exe or wscript.exe.
6+
* Added functionality for throttling lots of small file writes.
7+
* Added support for WMI.GetObject.Run().
8+
* Added support for ADODBStream.flush().
9+
* Added support for InternetExplorer.Application.
10+
* Added support for XMLHttpRequest.
11+
* Added some stubbed JQuery functionality.
12+
* Added support for ScheduleService.
13+
* Track IOCs being passed through the '|' operator in analyzed JS code.
14+
* Added support for WindowsInstaller.installer.
15+
16+
17+

_run.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ const path = require("path");
44
const walk = require("walk-sync");
55
const argv = require("./argv.js").run;
66

7+
function list_delete(arr, item) {
8+
for( var i = 0; i < arr.length; i++){
9+
10+
if ( arr[i] === item) {
11+
arr.splice(i, 1);
12+
i--;
13+
}
14+
}
15+
return arr;
16+
}
17+
18+
// Track whether we should return an error shell code or not.
19+
var single_sample = false;
20+
721
// Read and format JSON flag documentation
822
if (argv.help || process.argv.length === 2) {
923
const columnify = require("columnify");
@@ -72,7 +86,13 @@ const [targets, options] = args.functionalSplit(fs.existsSync);
7286
// Array of {filepath, filename}
7387
const tasks = [];
7488

75-
const [folders, files] = targets.functionalSplit(path => fs.statSync(path).isDirectory());
89+
var [folders, files] = targets.functionalSplit(path => fs.statSync(path).isDirectory());
90+
91+
// The output dir does not have samples to analyze.
92+
const outputDir = argv["output-dir"] || "./";
93+
if (outputDir != "./") {
94+
folders = list_delete(folders, outputDir);
95+
}
7696

7797
files
7898
.map(filepath => ({
@@ -105,14 +125,16 @@ if (argv.threads === 0) q.concurrency = Infinity;
105125
else if (argv.threads) q.concurrency = argv.threads;
106126
else q.concurrency = require("os").cpus().length;
107127

108-
if (tasks.length > 1) // If batch mode
109-
if (argv.threads)
128+
if (tasks.length > 1) { // If batch mode
129+
if (argv.threads) {
110130
console.log(`Analyzing ${tasks.length} items with ${q.concurrency} threads`)
111-
else
112-
console.log(`Analyzing ${tasks.length} items with ${q.concurrency} threads (use --threads to change this value)`)
113-
131+
}
132+
else {
133+
console.log(`Analyzing ${tasks.length} items with ${q.concurrency} threads (use --threads to change this value)`)
134+
}
135+
}
136+
114137
// queue the input files for analysis
115-
const outputDir = argv["output-dir"] || "./";
116138
tasks.forEach(({filepath, filename}) => q.push(cb => analyze(filepath, filename, cb)));
117139

118140
let completed = 0;
@@ -123,6 +145,10 @@ q.on("success", () => {
123145
console.log(`Progress: ${completed}/${tasks.length} (${(100 * completed/tasks.length).toFixed(2)}%)`);
124146
});
125147

148+
// Exit with a meaningful return code if we are only analyzing 1 sample.
149+
single_sample = (q.length == 1);
150+
151+
// Start analyzing samples.
126152
q.start();
127153

128154
function analyze(filepath, filename, cb) {
@@ -142,7 +168,8 @@ function analyze(filepath, filename, cb) {
142168
if (!argv.preprocess)
143169
console.log("Hint: if the script is heavily obfuscated, --preprocess --unsafe-preprocess can speed up the emulation.");
144170
worker.kill();
145-
if (argv.debug) process.exit(2);
171+
// Useful analysis may have occurred.
172+
process.exit(0);
146173
cb();
147174
}, timeout * 1000);
148175

@@ -169,9 +196,12 @@ function analyze(filepath, filename, cb) {
169196
* If the error is about a weird \"Unknown ActiveXObject\", try --no-kill.
170197
* Otherwise, report a bug at https://github.com/CapacitorSet/box-js/issues/ .`);
171198
}
199+
if (code != 0) {
200+
final_code = code;
201+
}
172202
clearTimeout(killTimeout);
173203
worker.kill();
174-
if (argv.debug) process.exit(code);
204+
if (argv.debug || single_sample) process.exit(code);
175205
cb();
176206
});
177207

0 commit comments

Comments
 (0)