chinda_fall_desu’s diary

竹内豊の日記

ヒューマンコンピューターインターフェースをもっと知りたいなー

pythonとtelnetで通信を行う

telnetsshのどちらもほかのコンピュータと接続するための仕組みであるが、telnetは通信を暗号化しないためその内容を覗き見られる危険性がある。
サーバを自分で作って、wiresharkで通信を覗いてみる。


(1)telnetで通信を行う
・サーバ

import socket
import subprocess

bind_host="0.0.0.0"
bind_port=50000
pw="password is 12345\n"

server=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_host, bind_port))
server.listen(5)
print("host: "+bind_host)
print("port: "+str(bind_port))

while True:
    client, addr=server.accept()
    print("from:"+ addr[0]+" "+str(addr[1]))
    while True:
        print("waiting for his response...")
        rec=client.recv(1024)
        client.send(pw.encode("utf-8"))

        if len(rec)==0:
            client.close()
            break

・クライアント

telnet 192.168.129.17 50000
Trying 192.168.129.17...
Connected to 192.168.129.17.
Escape character is '^]'.
Connection closed by foreign host.
hi
password is 12345

クライアントはサーバに接続してメッセージを送るとサーバから "password is 12345" が送られる。
だがこの内容は覗き見られる可能性がある。



(2)Wiresharkで内容を覗く
Wiresharkで上記のサーバとクライアント間の通信を覗くと下記が得られた。
・クライアント側が送った情報
f:id:chinda_fall_desu:20200128224826p:plain
・サーバ側が送った情報
f:id:chinda_fall_desu:20200128224955p:plain


次回はsshで同様のことを行う。


(間違い等あればコメントよろしくお願いいたします。)