This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Piorjade's profile picture

modEM - A custom modem peripheral wrapper

Started by Piorjade, 21 December 2016 - 05:08 PM
Piorjade #1
Posted 21 December 2016 - 06:08 PM
modEM - A custom modem peripheral wrapper

(I couldn't think of a name)


What this thing does:
SpoilerIt basically builds up a connection between two computers in a more secure way than RedNet.

How it works:
  • The host specifies a channel for the connection, the 2nd computer connects to it
  • Ones the host recognizes a 2nd connection, it generates a random number (between 1 and 65535) and passes it to the 2nd computer.
  • He then generates a random string, containing symbols and numbers, and passes that to the 2nd computer too.
  • The host then closes the channel and opens a new one using the new generated number.
  • The 2nd computer connects to that using the number the host gave him.
Now why is that all necessary?
  • The API passes a random number and opens a new channel on that to prevent from a 3rd party being able to listen on the connection between the 2 computers.
    • Sure he can guess the channel but it'd need a while.
  • It also passes a random string to the 2nd computer, because it ENCRYPTS the messages using that string.
    • Which leads to a higher security if a 3rd party is listening on that channel too.
A side effect:
Ones the host or the client leaves the connection, they'll have to make a new one.

How to build up a basic connection (example):

SpoilerHOST COMPUTER CODE:

os.loadAPI("/modEM")

modEM.host(1, "top")

while true do
  print(modEM.receive())
end

CLIENT COMPUTER CODE:

os.loadAPI("/modEM")
print("opening")
modEM.open("top")
print("Connecting")
local ok, err = modEM.connect(1)

if ok == false then
  printError(tostring(err))
  return
end
local e = "hello"

while true do

  e = read()
  local ok = modEM.send(e)

  if ok == false then
	printError(tostring(err))
	return
  end
end

WHAT TO DO:
  • Set up a modem on the top (on both computers)
  • Start up the host file first
  • Start up the client file
  • Start writing messages on the client computer and watch them getting printed on the host
  • Disconnect the client or host (for example by rebooting) and realize that you have no way of reconnecting



Download:

Pastebin

pastebin get D5RDJYE6 modEM

Credits:

Password based encryption - By PixelToast


If you have any questions, feel free to ask me :)/>
Edited on 21 December 2016 - 05:11 PM
Mao Zedong #2
Posted 21 December 2016 - 07:26 PM
So this is like Diffie-Hellman but more silly? What if a third party intercepts the random string?

Sure he can guess the channel but it'd need a while.

When sniffing the data, you can copy the data offline, and compute the hash. It would take a tiny fraction of a second to crack offline.
Edited on 21 December 2016 - 06:33 PM
KingofGamesYami #3
Posted 21 December 2016 - 07:28 PM
Sending the string used to encrypt really makes the encryption useless. Anyone doing any sort of wireless hacking will simply intercept it and use it to decrypt all the messages.
Piorjade #4
Posted 21 December 2016 - 07:39 PM
Well we're talking about Minecraft here, folks.

Your (in this situation) friend needs to know which channel to connect to. (Again, between 1 and 65535, so the 3rd guy (I'm calling him "hacker") needs to know that)

The rest is already explained.

So basically to even know what the string is, the "hacker" needs to get the message with the string too, but to get it he needs to know to which channel they connect.

Sure, it sounds kinda dumb but practically it's pretty good for servers if you want to be "protected" from the "hacker".

EDIT: Need to try something out
Edited on 21 December 2016 - 06:44 PM
KingofGamesYami #5
Posted 21 December 2016 - 07:51 PM
Well we're talking about Minecraft here, folks.
Your (in this situation) friend needs to know which channel to connect to. (Again, between 1 and 65535, so the 3rd guy (I'm calling him "hacker") needs to know that)
The rest is already explained.

On line 265 you give the "hacker" this information.
Piorjade #6
Posted 21 December 2016 - 07:55 PM
Well we're talking about Minecraft here, folks.
Your (in this situation) friend needs to know which channel to connect to. (Again, between 1 and 65535, so the 3rd guy (I'm calling him "hacker") needs to know that)
The rest is already explained.

On line 265 you give the "hacker" this information.

On the channel, which the 2 people specified.

If you somehow want to find out, which channel it is, you'd need to open up all channels and listen on them at the same time.

With one computer you can open up 129 channels, maximum.

The 2 users specify ANY channel they want, between 1 and 65535.
The "hacker" would need about 500 –> 86 (6 modems per comp.) computers to cover every channel if he REALLY wants to get the key.

To clear that up:
Example people:
Tim (host)
Paul (client)
Bob (hacker)

Tim tells Paul (however, for example via Skype) which channel they should connect to. –> Bob doesn't know which they specified

Tim starts the program up, Paul starts his program AFTER that (I'm reffering to the example codes for now).
–> Ones Paul connects, Tim's program generates a new channel-number, a key and sends them both to Paul (well technically to everyone in their channel)
–> Tim immidiently closes his connection, opens a new one on the generated channel and listens on that one
–> Paul immidiently closes his connection too, connects to the channel he got and uses the key he got to decrypt and encrypt every message he gets/sends

This is the most simple explanation I could think of.
Edited on 21 December 2016 - 07:09 PM
Exerro #7
Posted 21 December 2016 - 07:59 PM
Assuming one computer is a server that is active a lot of the time, with clients connecting every now and then, the attacker would easily be able to find the channel the server is using long before the client even connected by pinging all channels and seeing which get a response. It could then listen to those channels and intercept all the traffic, and as KingOfGamesYami pointed out, it'd then be able to spy on all communications between the server and client.
KingofGamesYami #8
Posted 21 December 2016 - 08:03 PM
Actually, the hacker needs 512 modems (128 channels / modem). He only needs 86 computers (6 modems / computer). This is easily achievable due to the cheap recipes.
Piorjade #9
Posted 21 December 2016 - 08:07 PM
Assuming one computer is a server that is active a lot of the time, with clients connecting every now and then, the attacker would easily be able to find the channel the server is using long before the client even connected by pinging all channels and seeing which get a response. It could then listen to those channels and intercept all the traffic, and as KingOfGamesYami pointed out, it'd then be able to spy on all communications between the server and client.

But it's not meant to be used as a server. As rebooting a client leads to not having the key.
You could do that with pinging, depending on if the "host" actually does something with your message. (modEM.receive() decrypts the received message too so idk how you'd "ping" a "host")

Even if you know which channel they do their messaging, you'd still need the key. And I don't remember sharing it all the time.

Actually, the hacker needs 512 modems (128 channels / modem). He only needs 86 computers (6 modems / computer). This is easily achievable due to the cheap recipes.

Yeah thanks for clearing that up, but again, it's not really worth it :P/>
Aaaaand I still don't remember sharing the key between encrypted messages O.o.
Only when they "connect", then you'd need to already have that 86 computer-setup before a connection even gets initiated.