Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script src="/rtl/jquery.js"></script>
- <script>
- $(function() {
- function print(txt) {
- $("#console").append(txt+"\n");
- window.scrollTo(0, document.body.scrollHeight);
- };
- var host = "<?lsp=request:url():gsub("^http","ws")?>";
- var s;
- try { s = new WebSocket(host); } catch(e) {}
- if( ! s ) {
- print("WebSocket not supported");
- return;
- }
- s.onopen = function() {
- print("WebSocket connected. Waiting for response.");
- };
- s.onmessage = function (e) {
- if(e.data instanceof Blob) {
- var f = new FileReader();
- f.onload = function(e) { print(e.target.result) };
- f.readAsText(e.data);
- }
- else {
- print(e.data);
- }
- };
- });
- </script>
- </head>
- <body>
- <pre id="console"></pre>
- </body>
- </html>
- <?lsp
- local url="http://btis.vn/mqtt.json"
- local mqttT={} -- List of all MQTT clients
- local ws -- WebSocket
- local file -- file where we dump the output
- local function onpub(info, msg) -- MQTT publish callback
- if file then
- file:write(info) file:write"\n" file:write(msg) file:write"\n"
- end
- local ok,err = ws:write(info, true)
- if not ws:write(info,true) or (#msg > 0 and not ws:write(msg)) then
- for _,mqtt in pairs(mqttT) do mqtt:disconnect() end
- if file then file:close() file=nil end
- end
- end
- local function startMQTT(ip, info) -- Create and connect one MQTT client
- ba.socket.event(function()
- local mqtt,err=require"mqttc".connect(ip, function(topic,msg)
- onpub(string.format("%s: %s: %s",info,ip,topic), msg) end)
- if mqtt then
- table.insert(mqttT, mqtt)
- mqtt:subscribe("#") -- Muahahaha
- mqtt:run()
- end
- end)
- end
- if request:header"Sec-WebSocket-Key" then -- If a WebSocket request
- ws = ba.socket.req2sock(request) -- Upgrade to a WebSocket connection
- if ws then
- -- Create an HTTP object and send an MQTT query to Shodan
- local http = require"httpm".create{shark=mako.sharkclient()}
- http:timeout(60*1000) -- Shodan can be slow
- local rsp,err = http:json(url)
- if true then -- If JSON response OK
- -- file = _G.io.open(string.format("/tmp/mqtt%d.txt",ba.rnd()),"w")
- ws:event(function() while ws:read() do end end, "s")
- -- for k,v in ipairs(rsp.matches) do
- startMQTT('test.mosquitto.org','com')
- -- end
- return -- OK
- end
- ws:write("response err: "..(err or "unknown"))
- end
- return -- Done
- end
- response:setheader("x-xss-protection","1; mode=block")
- response:setheader("content-security-policy",
- "default-src 'self'; connect-src http: https: ws: wss:; script-src 'self' 'unsafe-inline'")
- response:setheader("x-frame-options","SAMEORIGIN")
- response:setheader("x-content-type","nosniff")
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement