Advertisement
DOGGYWOOF

Rednet Fake broadcaster

Sep 25th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. -- Function to load DNS entries from the /DNS directory
  2. local function loadDNS()
  3. local dns = {}
  4. for _, file in ipairs(fs.list("/DNS")) do
  5. local f = fs.open("/DNS/" .. file, "r")
  6. local ip = f.readAll()
  7. f.close()
  8. dns[file] = ip
  9. end
  10. return dns
  11. end
  12.  
  13. -- Function to log DNS connections
  14. local function logConnection(url, ip)
  15. local logFile = fs.open("dns_log.txt", "a")
  16. logFile.writeLine("URL: " .. url .. ", IP: " .. ip .. ", Time: " .. textutils.formatTime(os.time(), true))
  17. logFile.close()
  18. end
  19.  
  20. -- Function to load the stored password from /DNS/locked.cfg
  21. local function loadPassword()
  22. local filePath = "/DNS/locked.cfg"
  23. if fs.exists(filePath) then
  24. local file = fs.open(filePath, "r")
  25. local password = file.readAll()
  26. file.close()
  27. return password
  28. end
  29. return nil -- No password file found
  30. end
  31.  
  32. -- Function to handle DNS requests
  33. local function handleDNSRequest(dns, senderID, url)
  34. local storedPassword = loadPassword()
  35. if storedPassword then
  36. rednet.send(senderID, "PASSWORD_REQUIRED") -- Ask for the password
  37.  
  38. local timer = os.startTimer(10) -- Wait for 10 seconds for a response
  39. while true do
  40. local event, id, message = os.pullEvent()
  41. if event == "rednet_message" and id == senderID then
  42. if message == storedPassword then
  43. if dns[url] then
  44. rednet.send(senderID, dns[url])
  45. logConnection(url, dns[url])
  46. else
  47. spam404(senderID, 5) -- Spam 404 messages
  48. end
  49. else
  50. rednet.send(senderID, "AUTH_FAILED")
  51. end
  52. break
  53. elseif event == "timer" and id == timer then
  54. rednet.send(senderID, "TIMEOUT")
  55. break
  56. end
  57. end
  58. else
  59. if dns[url] then
  60. rednet.send(senderID, dns[url])
  61. logConnection(url, dns[url])
  62. else
  63. spam404(senderID, 5) -- Spam 404 messages
  64. end
  65. end
  66. end
  67.  
  68. -- Function to spam 404 messages
  69. local function spam404(senderID, count)
  70. for i = 1, count do
  71. rednet.send(senderID, "404_NOT_FOUND")
  72. os.sleep(0.5) -- Wait a bit between messages
  73. end
  74. end
  75.  
  76. -- Automatically find and open the first available modem
  77. local function openModem()
  78. local sides = {"top", "bottom", "left", "right", "front", "back"}
  79. for _, side in ipairs(sides) do
  80. if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  81. rednet.open(side)
  82. return side
  83. end
  84. end
  85. print("Error: No modem found.")
  86. return nil
  87. end
  88.  
  89. -- Prompt for a fake DNS Computer ID
  90. local function promptForFakeID()
  91. print("Enter Fake DNS Computer ID:")
  92. return read()
  93. end
  94.  
  95. -- Main DNS server function
  96. local function runDNSServer()
  97. local modemSide = openModem()
  98. if not modemSide then return end
  99.  
  100. local dns = loadDNS()
  101. local fakeID = promptForFakeID() -- Get the fake ID
  102. print("DNS Server is running on " .. modemSide .. " modem. Listening for requests with ID: " .. fakeID .. "...")
  103.  
  104. while true do
  105. local senderID, url = rednet.receive()
  106. handleDNSRequest(dns, senderID, url)
  107. end
  108. end
  109.  
  110. -- Main execution
  111. runDNSServer()
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement