Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lastHostID = 0
- local lasttMessage = ""
- local tHosts = { }
- --[[
- lPort = destination - Port
- rPort = reply / sender - Port
- ]]
- --[[
- Add check for double /sniff - hosts/
- do not close side if double!
- ]]
- local
- private = { }
- --attack = {
- dos = {
- dns_client_error = nil,
- dns_server_error = nil,
- dns_flood = nil,
- rns_packet = nil
- }
- --}
- --network = {
- --gather = {
- scann = {
- findRednet = nil,
- lookupHosts = nil
- }
- sniff = {
- addHost = nil,
- getHost = nil,
- getHostList = nil,
- parallel = nil,
- parseRednet = nil,
- reload = nil,
- reloadAll = nil,
- removeAllHosts = nil,
- removeHost = nil,
- run = nil,
- setHost = nil,
- stop = nil
- }
- --},
- spoof = {
- dnsReply = nil,
- dnsRequest = nil,
- forward = nil, -- soon
- host = nil,
- message = nil,
- request = nil -- IMPORTANT SOON
- }
- wired = {
- execute = nil,
- getMethods = nil,
- getNames = nil,
- getType = nil,
- isPresent = nil
- }
- --}
- dos.dns_client_error = function(
- lPort,
- rPort) -- (opt)
- end
- dos.dns_server_error = function(
- lPort,
- rPort) -- (opt)
- end
- dos.dns_flood = function(
- mSide,
- lPort, -- (all)
- sProtocol, -- (all)
- nCount, -- (opt)
- nTimer)
- if type(sProtocol) ~= "string" and sProtocol ~= nil then
- error("Protocol as string expected", 0)
- end
- if type(nCount) ~= "number" then
- nCount = 10
- end
- local modem = peripheral.wrap( private.simpleSide(mSide) )
- local nHost = sniff.addHost(
- 65535,
- nil,
- mSide)
- local dosHosts = { }
- while true do
- os.startTimer(0.05)
- local sEvent, vData, nPort, nReplyPort, tMessage, nDistance
- = os.pullEvent()
- for _, dosHost in pairs(dosHosts) do
- for i=1, nCount do
- local newRPort = math.random(1, 65535)
- spoof.dnsReply(
- modem,
- dosHost.nReplyPort,
- newRPort,
- dosHost.sHostname == nil and tostring( math.random(1, 65535) )
- or dosHost.sHostname,
- dosHost.sProtocol)
- end
- end
- if sEvent == "sniff_message" and vData == nHost then
- local message = sniff.parseRednet(tMessage)
- if message
- and tMessage.sProtocol == "dns"
- and type(message.sType) == "string"
- and message.sType == "lookup"
- and (sProtocol == nil or
- sProtocol == tMessage.sProtocol)
- and lPort == nil or lPort == nReplyPort then
- dosHosts[os.startTimer(2)] =
- {
- nReplyPort = nReplyPort,
- sProtocol = message.sProtocol,
- sHostname = message.sHostname
- }
- end
- elseif sEvent == "timer" and type(dosHosts[vData]) == "table" then
- dosHosts[vData] = nil
- elseif sEvent == "timer" and vData == nTimer then
- break
- end
- end
- sniff.removeHost(nHost)
- end
- -- RE NEW SEND PACKET
- dos.rns_packet = function(
- lPort,
- rPort,
- sSide,
- sProtocol,
- nCount,
- nTimer)
- end
- private.tableContains = function(tTable, vmVar)
- for _, vsVar in pairs(tTable) do
- if vsVar == vmVar then
- return true
- end
- end
- return false
- end
- private.fullPort = function(vPort)
- tPorts = vPort
- if type(vPort) ~= "table" then
- tPorts = { private.simplePort(vPort) }
- end
- for i, nPort in pairs(tPorts) do
- if not (nPort >= 0 and nPort <= 65535) then
- table.remove(tPorts, i)
- end
- end
- if #tPorts == 0 then
- error("Selected ports are out of range")
- end
- return tPorts
- end
- private.simplePort = function(vPort)
- if type(vPort) == "string" then
- vPort = tonumber(vPort)
- elseif type(vPort) ~= "number" then
- error("Port as number or string expected", 0)
- end
- if vPort >= 0 and vPort <= 65535 then
- return vPort
- end
- error("Port is not in range", 0)
- end
- private.updateSide = function(vSide)
- local tAviable = peripheral.getNames()
- local tSides = vSide
- if #tAviable == 0 then
- error("No modems found", 0)
- end
- if type(vSide) == "string" then
- tSides = { vSide }
- elseif type(vSide) ~= "table" then
- return tAviable
- end
- for i, sSide in pairs(tSides) do
- local bLost = true
- for _, avSide in pairs(tAviable) do
- if sSide == avSide then
- bLost = false
- break
- end
- end
- if bLost then
- table.remove(tSides, i)
- end
- end
- if #tSides == 0 then
- error("Selected modems not found", 0)
- end
- return tSides
- end
- private.fullSide = function(vSide)
- local tAviable = peripheral.getNames()
- local tSides = vSide
- if #tAviable == 0 then
- error("No modems found", 0)
- end
- if type(vSide) ~= "table" then
- tSides = { private.simpleSide(vSide) }
- end
- for i, sSide in pairs(tSides) do
- local bLost = true
- for _, avSide in pairs(tAviable) do
- tSides[i] = private.simpleSide( sSide )
- if sSide == avSide then
- bLost = false
- break
- end
- end
- if bLost then
- table.remove(tSides, i)
- end
- end
- if #tSides == 0 then
- error("Selected modems not found", 0)
- end
- return tSides
- end
- private.simpleSide = function(vSide)
- if type(vSide) ~= "string" then
- error("String as side expected", 0)
- end
- if not private.tableContains({
- "top", "bottom",
- "left", "right",
- "front", "back"
- }, vSide) then
- error("Modem side not found", 0)
- end
- return vSide
- end
- scann.findRednet = function(
- mSide,
- nTimeout,
- sProtocol)
- local tRN = { }
- if type(nTimeout) ~= "number" then
- error("Timout as number expected", 0)
- end
- local nHost = sniff.addHost(
- 65533,
- nil,
- mSide)
- local nTimer = os.startTimer(nTimeout)
- while true do
- local sEvent, vData, nPort, nReplyPort, tMessage, nDistance
- = os.pullEvent()
- if sEvent == "siff_message" then
- local message = sniff.parseRednet(tMessage)
- if message
- and not private.tableContains(tRN, message.nRecipient) then
- table.insert(tRN, message.nRecipient)
- end
- elseif sEvent == "timer" and nTimer == vData then
- break
- end
- end
- sniff.removeHost(nHost)
- return tRN
- end
- scann.lookupHosts = function(
- mSide,
- sProtocol,
- rPort)
- local modem = peripheral.wrap( private.simpleSide( mSide ) )
- local tDnsHosts = { }
- if type(sProtocol) ~= "string" then
- error("Protocol as string expected", 0)
- end
- if type(rPort) ~= "number" then
- rPort = math.random(0, 65535)
- end
- local nHost = sniff.addHost(
- rPort,
- nil,
- mSide)
- spoof.dnsRequest(
- modem,
- rPort,
- sProtocol)
- local nTimer = os.startTimer(2)
- while true do
- local sEvent, vData, nPort, nReplyPort, tMessage, nDistance
- = os.pullEvent()
- if sEvent == "sniff_message" then
- local message = sniff.parseRednet(tMessage)
- if message
- and nPort == rPort
- and tMessage.sProtocol == "dns"
- and type(message.sType) == "string"
- and message.sType == "lookup response"
- and type(message.sProtocol) == "string"
- and message.sProtocol == sProtocol then
- table.insert(tDnsHosts,{
- sHostname = message.sHostname,
- nRecipient = nReplyPort
- })
- end
- elseif sEvent == "timer" and nTimer == vData then
- break
- end
- end
- sniff.removeHost(nHost)
- return tDnsHosts
- end
- sniff.addHost = function(
- lPort,
- rPort,
- vSide)
- lastHostID = lastHostID + 1
- tHosts[ lastHostID ] =
- {
- ID = lastHostID,
- lPort = private.fullPort(lPort),
- rPort = (rPort == nil)
- and "true" or private.fullPort(rPort),
- sSide = private.fullSide(vSide)
- }
- for _, mSide in pairs( tHosts[lastHostID].sSide ) do
- for _, mPort in pairs( tHosts[lastHostID].lPort ) do
- peripheral.call(mSide, "open", mPort)
- end
- end
- return lastHostID
- end
- sniff.getHost = function(ID)
- if type(tHosts[ID]) == "table" then
- return tHosts[ID]
- else
- error("Host not found", 0)
- end
- end
- sniff.getHostList = function()
- local list = { }
- for i in pairs(tHosts) do
- table.insert(list, i)
- end
- return list
- end
- sniff.parallel = function()
- if private.sniff_bRunning then
- error("Sniffer is already running", 0)
- end
- private.sniff_bRunning = true
- while true do
- if not private.sniff_bRunning then
- sniff.stop()
- end
- local sEvent, vData, nPort, nReplyPort, tMessage, nDistance
- = private.native_pullEventRaw()
- if sEvent == "modem_message"
- and textutils.serialize(tMessage) ~= lasttMessage then
- lasttMessage = textutils.serialize(tMessage)
- for _, tHost in pairs(tHosts) do
- if private.tableContains(tHost.sSide, vData)
- and private.tableContains(tHost.lPort, nPort) then
- if type(tHost.rPort) == "string"
- or private.tableContains(tHost.rPort, nReplyPort) then
- os.queueEvent(
- "sniff_message",
- tHost.ID,
- nPort,
- nReplyPort,
- tMessage,
- distance)
- end end
- end
- elseif sEvent == "peripheral_detach"
- and vData == "modem" then
- for ID in pairs(tHosts) do
- tHosts[ID].side = private.fullSide(side)
- end
- end
- end
- end
- sniff.parseRednet = function(tMessage)
- if type(tMessage) == "table"
- and type(tMessage.nRecipient) == "number"
- and type(tMessage.nMessageID) == "number" then
- return tMessage.message
- end
- return false
- end
- sniff.reload = function(ID)
- sniff.setHost(ID)
- end
- sniff.reloadAll = function()
- for _, tHost in pairs(tHosts) do
- sniff.reload(tHost.ID)
- end
- end
- sniff.removeAllHosts = function()
- for _, tHost in pairs(tHosts) do
- sniff.removeHost(tHost.ID)
- end
- end
- sniff.removeHost = function(ID)
- if type(tHosts[ID]) == "table" then
- for _, mSide in pairs( tHosts[ID].sSide ) do
- for _, mPort in pairs( tHosts[ID].lPort ) do
- local bFound = false
- for _, tHost in pairs(tHosts) do
- if private.tableContains(tHost.sSide, mSide)
- and private.tableContains(tHost.lPort, mPort) then
- bFound = true
- end
- end
- if bFound then
- break
- end
- peripheral.call(mSide, "close", mPort)
- end
- end
- tHosts[ID] = nil
- else
- error("Host not found", 0)
- end
- end
- private.native_pullEventRaw = os.pullEventRaw
- private.sniff_bRunning = false
- sniff.run = function()
- if private.sniff_bRunning then
- error("Sniffer is already running", 0)
- end
- private.sniff_bRunning = true
- private.native_pullEventRaw = os.pullEventRaw
- os.pullEventRaw = function(...)
- if not private.sniff_bRunning then
- sniff.stop()
- end
- local sEvent, vData, nPort, nReplyPort, tMessage, nDistance
- = private.native_pullEventRaw(...)
- if sEvent == "modem_message"
- and textutils.serialize(tMessage) ~= lasttMessage then
- lasttMessage = textutils.serialize(tMessage)
- for _, tHost in pairs(tHosts) do
- if private.tableContains(tHost.sSide, vData)
- and private.tableContains(tHost.lPort, nPort)
- and tHost.lPort == nPort then
- if type(tHost.rPort) == "string"
- or tHost.rPort == nReplyPort then
- os.queueEvent(
- "sniff_message",
- tHost.ID,
- nPort,
- nReplyPort,
- tMessage,
- distance)
- end end
- end
- elseif sEvent == "peripheral_detach"
- and vData == "modem" then
- for ID in pairs(tHosts) do
- tHosts[ID].side = private.fullSide(side)
- end
- end
- return sEvent, vData, nPort, nReplyPort, tMessage, nDistance
- end
- end
- sniff.setHost = function(
- ID,
- lPort,
- rPort,
- sSide)
- if type(tHosts[ID]) == "table" then
- local tlPort = tHosts[ID].lPort
- local trPort = tHosts[ID].rPort
- local tsSide = tHosts[ID].sSide
- local temp_lhID = lastHostID
- if type(lPort) == "number"
- or type(lPort) == "table" then
- tlPort = private.fullPort(lPort)
- end
- if type(rPort) == "number"
- or type(rPort) == "table" then
- tHosts[ID].rPort = private.fullPort(rPort)
- elseif type(rPort) == "string" then
- trPort = "true"
- end
- if type(sSide) == "string"
- or type(sSide) == "table" then
- tsSide = private.fullSide(sSide)
- end
- sniff.removeHost(ID)
- lastHostID = ID - 1
- sniff.addHost(tlPort, trPort, tsSide)
- lastHostID = temp_lhID
- else
- error("Host not found", 0)
- end
- end
- sniff.stop = function()
- if private.sniff_bRunning then
- os.pullEventRaw = private.native_pullEventRaw
- private.sniff_bRunning = false
- else
- error("Sniffer is not running", 0)
- end
- end
- spoof.dnsReply = function(
- modem,
- lPort,
- rPort,
- sHostname,
- sProtocol)
- if type(sHostname) ~= "string" then
- error("Hostname expected", 0)
- end
- if type(sProtocol) ~= "string" then
- error("Protocol expected", 0)
- end
- spoof.message(
- modem,
- lPort,
- rPort,
- rPort,
- {
- sType = "lookup response",
- sHostname = sHostname,
- sProtocol = sProtocol
- },
- "dns")
- end
- spoof.dnsRequest = function(
- modem,
- rPort,
- sProtocol,
- sHostname)
- if type(sProtocol) ~= "string" then
- error("Protocol expected", 0)
- end
- spoof.message(
- modem,
- 65535,
- rPort,
- rPort,
- {
- sType = "lookup",
- sProtocol = sProtocol,
- sHostname = sHostname
- },
- "dns")
- end
- spoof.forward = function(
- mSide,
- rllport,
- rlrport,
- fklport,
- fkrport,
- isRednet,
- sProtocol,
- isRCroutine)
- local foo = function()
- end
- if isRCroutine then
- return coroutine.create(foo)
- else
- foo()
- end
- end
- spoof.host = function(
- modem,
- vPort,
- sProtocol)
- -- Active spoofing (repeat) [dns]
- end
- spoof.message = function(
- modem,
- destPort,
- replyPort,
- nRecipient,
- message,
- sProtocol)
- if not modem then
- error("No modem selected", 0)
- end
- destPort = private.simplePort(destPort)
- replyPort = private.simplePort(replyPort)
- nRecipient = private.simplePort(nRecipient)
- if type(sProtocol) ~= "string" then
- sProtocol = ""
- end
- modem.transmit(destPort, replyPort,
- {
- nRecipient = nRecipient,
- message = message,
- nMessageID = math.random(1, 2147483647),
- sProtocol = sProtocol
- })
- end
- spoof.request = function()
- -- Setup sniff
- -- Send message
- -- Wait for message
- -- Parse message
- -- Return
- end
- wired.execute = function(
- modem,
- sName,
- sMethod,
- ...)
- if modem.isWireless() then
- error("Only for wired modems", 0)
- end
- if type(sName) ~= "string" then
- error("Name expected", 0)
- end
- return modem.callRemote(sName, sMethod, ...)
- end
- wired.getMethods = function(modem, sName)
- if modem.isWireless() then
- error("Only for wired modems", 0)
- end
- if type(sName) ~= "string" then
- error("Name expected", 0)
- end
- return modem.getMethodsRemote(sName)
- end
- wired.getNames = function(modem)
- if modem.isWireless() then
- error("Only for wired modems", 0)
- end
- return modem.getNamesRemote()
- end
- wired.getType = function(modem, sName)
- if modem.isWireless() then
- error("Only for wired modems", 0)
- end
- if type(sName) ~= "string" then
- error("Name expected", 0)
- end
- return modem.getTypeRemote(sName)
- end
- wired.isPresent = function(modem, sName)
- if modem.isWireless() then
- error("Only for wired modems", 0)
- end
- if type(sName) ~= "string" then
- error("Name expected", 0)
- end
- return modem.isPresentRemote(sName)
- end
- return {
- dos = dos,
- scann = scann,
- sniff = sniff,
- spoof = spoof,
- wired = wired
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement