Ccmmutty logo
Commutty IT
2
9 min read

hack the box ~魔法使いへの道~ (その5) PythonでRDPブルートフォースアタック①

https://cdn.magicode.io/media/notebox/5d2d3ce4-754c-4729-8605-c219d38c0b24.jpeg

はじめに

セキュリティに関する知識は,現代社会においてますます重要性を増しています.それに伴い,セキュリティに関する技術もますます需要が高まっています.その中でも,ホワイトハッカーとしてのスキルは,現代のエンジニアにとって非常に重要なものとなっています.本記事では,Pythonを使ったセキュリティの学習を目的として,Hack the Boxでブルートフォースアタックを学ぶ方法について解説します.

ブルートフォースアタックとは

ブルートフォースアタックとは,暗号化された情報を解読するために,全ての可能性を総当たりで試す手法です.この手法は非常に時間がかかるため,現代の暗号化技術では,この手法を防ぐための対策が施されています.しかし,まだまだ多くのサイトやシステムでは,強固なパスワードが使用されていないため,ブルートフォースアタックで簡単にアクセスが可能な状態になっている場合があります.

Hack the Boxとは

Hack the Boxは,ホワイトハッカーを目指したエンジニアのための,実践的なセキュリティ学習プラットフォームです.Hack the Boxでは,仮想マシンに対する攻撃や,Webサイトに対する攻撃など,様々な攻撃シナリオが用意されており,エンジニアは自由に攻撃を行い,セキュリティのスキルを磨くことができます.
Hack the BoxをやるためのPCの設定方法はこちら

ブルートフォースアタックの実践

Hack the Boxでブルートフォースアタックを行うためには,まずPythonの環境を構築する必要があります.Pythonは,ブルートフォースアタックにおいて非常に便利な言語であり,Hack the Boxでも広く使用されています.Pythonの環境構築には,AnacondaやMinicondaなどのツールが利用できます.

Minicondaのインストール

Minicondaは,Pythonのパッケージ管理ツールであり,Pythonの環境構築に非常に便利です.Minicondaをインストールするには,以下の手順を実行します.
こちらのサイト*1からダウンロードします.

Minicondaのインストール

基本的には「yes」かエンターでいけます.
┌──(maki㉿kali)-[~/Downloads]
└─$ sudo sh ./Miniconda3-latest-Linux-x86_64.sh -u
[sudo] maki のパスワード:

Welcome to Miniconda3 py39_4.12.0

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> 
======================================
End User License Agreement - Miniconda
======================================

Copyright 2015-2022, Anaconda, Inc.

All rights reserved under the 3-clause BSD License:

This End User License Agreement (the "Agreement") is a legal agreement between you and Anaconda, Inc. ("Anaconda") and governs your use of Miniconda.

Subject to the terms of this Agreement, Anaconda hereby grants you a non-exclusive, non-transferable license to:

  * Install and use the Miniconda,
  * Modify and create derivative works of sample source code delivered in Miniconda subject to the Terms of Service for the Repository (as defined hereinafter) available at https://www.anaconda.com/terms-of-service, and
  * Redistribute code files in source (if provided to you by Anaconda as source) and binary forms, with or without modification subject to the requirements set forth below.

Anaconda may, at its option, make available patches, workarounds or other updates to Miniconda. Unless the updates are provided with their separate governing terms, they are deemed part of Miniconda licensed to you as provided in t
his Agreement. This Agreement does not entitle you to any support for Miniconda.

Anaconda reserves all rights not expressly granted to you in this Agreement.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  * Neither the name of Anaconda nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

You acknowledge that, as between you and Anaconda, Anaconda owns all right, title, and interest, including all intellectual property rights, in and to Miniconda and, with respect to third-party products distributed with or through 
Miniconda, the applicable third-party licensors own all right, title and interest, including all intellectual property rights, in and to such products. If you send or transmit any communications or materials to Anaconda suggesting 
or recommending changes to the software or documentation, including without limitation, new features or functionality relating thereto, or any comments, questions, suggestions or the like ("Feedback"), Anaconda is free to use such 

Do you accept the license terms? [yes|no]
[no] >>> yes

Miniconda3 will now be installed into this location:
/root/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/miniconda3] >>> 
PREFIX=/root/miniconda3
Unpacking payload ...
Collecting package metadata (current_repodata.json): done                                                                                                                                                                              
Solving environment: done

# All requested packages already installed.

installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
no change     /root/miniconda3/condabin/conda
no change     /root/miniconda3/bin/conda
no change     /root/miniconda3/bin/conda-env
no change     /root/miniconda3/bin/activate
no change     /root/miniconda3/bin/deactivate
no change     /root/miniconda3/etc/profile.d/conda.sh
no change     /root/miniconda3/etc/fish/conf.d/conda.fish
no change     /root/miniconda3/shell/condabin/Conda.psm1
no change     /root/miniconda3/shell/condabin/conda-hook.ps1
no change     /root/miniconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change     /root/miniconda3/etc/profile.d/conda.csh
no change     /root/.zshrc
No action taken.
If you'd prefer that conda's base environment not be activated on startup, 
   set the auto_activate_base parameter to false: 

conda config --set auto_activate_base false

Thank you for installing Miniconda3!

もしエラーがでたら

ここで,下記のようなエラーが出た場合は,容量不足*2か権限関係で失敗している可能性があります.
私もこのようなエラーがでたため,仮想マシンの容量を50GBにして「sudo」つけて実行したら
成功しました.
Unpacking payload ... concurrent.futures.process._RemoteTraceback: ''' Traceback (most recent call last): File "concurrent/futures/process.py", line 368, in _queue_management_worker File "multiprocessing/connection.py", line 251, in recv TypeError: __init__() missing 1 required positional argument: 'msg' '''

エラー文

仮想環境の構築

Pythonの環境構築が完了したら,次に仮想環境を構築します.仮想環境とは,Pythonのパッケージを独立して管理するための環境であり,複数のプロジェクトを同時に管理することができます.
「sudo su」でrootに入ると(base)の仮想環境に入ることができます.
┌──(maki㉿kali)-[~/Downloads]
└─$ sudo su                                       
(base) ┌──(root㉿kali)-[/home/maki/Downloads]
└─#

参考記事

  • *1:Miniconda — Conda documentation
  • *2:Anacondaのインストールに失敗しMinicondaを入れた話

Discussion

コメントにはログインが必要です。