Last active
November 10, 2018 01:49
-
-
Save UlisseMini/7efb78251dc91fe85b9d86f63a17aba8 to your computer and use it in GitHub Desktop.
Program to pwn rednet comunications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Program to pwn rednet comunications | |
-- Options | |
-- WireDoplphin replay - prompt repeating coms with custom message & sender ids | |
-- WireDoplphin listen - just listen and display comunications | |
-- TODO | |
-- add listening at the same time as repeating | |
-- more commandline options (gnu standered parsing?) | |
-- log how meny messages from every computer id sent and what spam was filtered | |
local helptext = "Usage: WireDoplphin <option>\noptions are:\nreplay - prompt repeating coms with custom message & sender ids\nlisten - just listen and display comunications" | |
-- Manage args | |
local args = { ... } | |
if #args ~= 1 then | |
print(helptext) | |
return | |
end | |
-- Simple config variables | |
local VERSION = "WireDoplphin v0.3" | |
local logfile = "WireDoplphin.log" | |
local ignoreCount = 30 -- allow for 30 of the same message (set to 0 for no filter) | |
-- Variables | |
local math = require("math") -- for random ids | |
local options = {} -- Store functions in here | |
local chan = 65535 | |
-- If you get a lot of the same message start ignoring it | |
local messages = {} -- store messages | |
-- filled in lower down | |
local choice | |
local newmsg | |
local id | |
local modem | |
local ReceivedMessages = {} -- Store messages we have already processed | |
-- Find a modem and wrap it to the modem peripheral | |
for n, m in ipairs(peripheral.getNames()) do | |
if peripheral.getType(m) == "modem" then | |
modem = peripheral.wrap(m) | |
break | |
end | |
end | |
-- If you did not find a modem error | |
if not modem then | |
print("Failed to find modem.") | |
return | |
end | |
-- Add custom filters here | |
local function passesFilter(msg) | |
-- Check if the protocol is one char long | |
if msg.sProtocol and #msg.sProtocol == 1 then | |
return false | |
end | |
-- check if the message can be converted to a number | |
local testNum = tonumber(msg.message) | |
if testNum then | |
return false | |
end | |
-- Make sure it is a rednet comunication | |
if type(msg) ~= "table" then | |
return false | |
end | |
-- Make sure it has all the required indexes in the table | |
if not msg.nMessageID then return false end | |
if not msg.nRecipient then return false end | |
if not msg.message then return false end | |
-- Make sure they have valid message id's | |
if ReceivedMessages[msg.nMessageID] then return false end | |
-- Filters out repeating messages. | |
-- If ignoreCount = 0 then don't bother | |
if ignoreCount == 0 then return true end | |
-- Create the message index if needed. | |
if not messages[msg.message] then | |
messages[msg.message] = 0 | |
end | |
-- Add to the message index | |
messages[msg.message] = messages[msg.message] + 1 | |
-- check to see if it has repeated too meny times | |
if messages[msg.message] >= ignoreCount then | |
return false | |
end | |
-- otherwise return true | |
return true | |
end | |
-- Will be used later prolly | |
local function inTable(value, t) | |
for k, indexVal in ipairs(t) do | |
if value == indexVal then | |
return true | |
end | |
end | |
return false | |
end | |
-- Log stuff to a file | |
local function log(msg, filename) | |
local f = fs.open(filename, "a") | |
f.write(msg.."\n") | |
f.close() | |
end | |
-- Get rednet messages | |
local function receive() | |
-- In the rednet protocol replyChannel is the sender id | |
while true do | |
local _, _, _, replyChannel, msg = os.pullEvent("modem_message") | |
if passesFilter(msg) then | |
ReceivedMessages[msg.nMessageID] = true | |
return replyChannel, msg | |
end | |
end | |
end | |
-- Yeah i'm a pythoner, fight me | |
local function input(prompt) | |
if prompt then | |
io.write(prompt) | |
end | |
return io.read() | |
end | |
-- functions (one for every option) | |
function options.listen() | |
while true do | |
local chan, msg = receive() | |
print(textutils.serialise(msg)) | |
end | |
end | |
function options.replay() | |
while true do | |
local respchan, msg = receive() | |
-- Prompt the user to replay the message | |
print(textutils.serialise(msg)) | |
choice = input("replay (y/n/q): ") | |
if choice == "y" then | |
-- ask if they want to change the message | |
newmsg = input("New message: ") | |
if newmsg ~= "" then | |
msg.message = newmsg | |
end | |
-- ask if they want to spoof the sender id | |
id = input("Sender id: ") | |
id = tonumber(id) | |
-- if it fails to convert to a number then leave it unchanged. | |
if not id then | |
-- Later i could make it listen in parallel on its computerid | |
-- to get the response from the server. | |
id = respchan | |
end | |
local nMessageID = math.random(1, 2147483647) | |
ReceivedMessages[ nMessageID ] = true -- so we don't get our own messages | |
msg.nMessageID = nMessageID -- so rednet accepts our message | |
-- id is response channel, rednet likes it that way | |
modem.transmit(chan, id, msg) | |
print("Packet transmited") | |
elseif choice == "q" then | |
return | |
end | |
end | |
end | |
-- Check option | |
if not options[args[1]] then print(helptext) return end | |
-- Otherwise run | |
modem.open(chan) | |
print("Starting "..VERSION.."...") | |
options[args[1]]() | |
print("Goodbye, thank you for using "..VERSION) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment