2
2

More than 5 years have passed since last update.

ハック技術: Windows7ハック #1 Vagrant VirtualBoxで環境セットアップ編 (on Ubuntu)

Last updated at Posted at 2019-05-01

#ゆるいハッキング大会」に参加した。
ハッキング熱が高まった。

ハッキング・ラボのつくりかた」を勢いで購入。

今回は、ハッキング・ラボの作り方に載っているWindows7のやり方。

お約束

本記事は、
・防御の為に敵の攻撃を知る
・技術力向上
を目的としている為、記載内容を悪用する事は禁じます。
記載内容を実行した結果として生じた全ての事に、私は一切責任を負いません。

環境セットアップ

0. 自分のノートPC

 HP HP Spectre x360 Convertible 13-ac0XX/827E, BIOS F.31 04/27/2017
 Linux dsnote 4.15.0-48-generic #51~16.04.1-Ubuntu SMP Fri Apr 5 12:01:12 UTC 2019 x86_64 GNU/Linux

1. KaliLinux

ハック技術: KaliLinux on Docker - Qiita

2. VM関係ソフトウェアのインストール

Vagrant+VirtualBoxで構築する。
Vagrantは、VM環境の構築をInfrastructure as Code(IaC)的に出来る。
設定ファイルがあれば、どこでも同じ環境が構築可能。GUIでポチポチする必要がない。
実際に利用する仮想化ソフトウェアはVirtualBox。ただし、Vagrantは他の仮想化ソフトウェアもサポートしている。

・VirtualBox 5.1.x、Vagrant 1.9.6、PowerShell 2.0 以上
・VirtualBox 5.1.x、Vagrant 1.9.7、PowerShell 5 以上
・VirtualBox 5.2.x、Vagrant 2.0.1 以上、PowerShell 5以上

この組み合わせならいける様子だが、現行最新はVirtualBox6.0(2019/05/02現在)なので、6.0をインストールする

VirtualBox インストール

$ sudo apt-add-repository "deb https://download.virtualbox.org/virtualbox/debian xenial contrib"
$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add 
$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
$ sudo apt-get update
$ sudo apt-get install virtualbox-6.0
$ vboxmanage --version
6.0.6r130049
VirtualBox 6.0.6 Oracle VM VirtualBox Extension Pack インストール

「All supported platforms」からダウンロードして実行する。 

Vagrant インストール

https://www.vagrantup.com/downloads.html
ここからダウンロード。

$ sudo dpkg -i ~/Downloads/vagrant_2.2.4_x86_64.deb 
$ vagrant --version
Vagrant 2.2.4

3. Windows7のVM(90日無償版)を公式からダウンロード

Download virtual machines(MS公式)

MS公式提供のWindows7のvagrant boxでWindows7の仮想環境を構築する

MSはOSの検証目的というよりブラウザの互換性の検証目的でこれらの仮想マシンを配布しているよう

そんな感じなようです。ありがたやありがたや。
私がダウンロードしたのは、IE11/Win7のZipファイル。

ダウンロードが終わると、以下を実行。

$ cp ~/Downloads/IEE11.Win7.Vagrant.zip .
$ unzip IE11.Win7.Vagrant.zip

4. Vagrantの設定

$ vagrant init
$ vagrant box add hack_Win7IE11 "IE - Win7.box"

"IE - Win7.box"というのは、zipを解凍して出てきたもの。
boxファイルという、仮想環境のイメージファイル的なもの。

IaC的にVM環境を記述するのには、Vagrantfileに設定を書く。
Vagrantfileを以下のように編集。

Vagrant.configure("2") do |config|

 config.vm.box = "hack_Win7IE11"
 config.vm.provider "virtualbox" do |vb|
   vb.gui = true
   vb.memory = "2048"
 end
 config.vm.communicator = "winrm"
 config.winrm.username = "IEUser"
 config.winrm.password = "Passw0rd!"
 config.vm.network "private_network", type: "dhcp"
 config.vm.synced_folder ".", "/vagrant", disabled: true

end

ユーザ:IEUser
パスワード: Passw0rd!

$ sudo gem install winrm winrm-fs

5. VM Windows7 起動、初期設定

起動して再起動する。

 再起動することで、マウス統合が有効になり、ホストOSとゲストOSでスムーズにマウス操作が可能になる様子。

VM画面 デバイス->ネットワーク->ネットワーク設定 NATネットワークをホストオンリーアダプターに変更

VirtualBox 6.0でVMでホストオンリーアダプタでの接続をさせる - 俺的備忘録 〜なんかいろいろ〜
先にこの設定が必要かも?Vagrantでやっていたらその必要は無いはずだが。

(ライセンス認証の猶予期間を延長方法

 プロダクトキーなしでインストールしたら10日間試用可能。
 管理者権限でコマンドプロンプト起動、slmgrコマンド(実体はslmgr.vbs)を実行すると、
 確認・延長が可能。

> slmgr /dlv
Time remaining: ~~~ minute(s) (10 days(s))
Reaining Windows rearm count: ~~

などと表示されている部分を確認。

> slmgr /rearm

で、猶予期間がリセットされ、再起動を促される

Pingに応答する様に変更

ICMPリクエストをFirewallでフィルターしないようにする。
ControlPanel > System and Security > Windows Firewall > Advanced settings
Inbound Roules > File and Printer Sharing(Echo Request - ICMPv4-In) > Properties > General > Enable> Apply

Windows Updateを停止する

 実験環境では度々アップデートする必要ないので停止。
 Control Panel > System and Security > Windows Update > Change settings > Important updates
 「Never check for updates (not recommended)」

VirtualBox Guest Additionsの適用

VMの操作性が向上する。
デバイス > Guest Additions CDイメージの挿入 > ダウンロード > 挿入 > Run VBoxWindowsAdditions.exe

ハッキングラボの作り方では日本語キーボードの設定をしているが、私はUSキーボードなのでやらない
ドラッグ&ドロップでファイル共有出来る様に設定

デバイス > ドラッグ&ドロップ > 双方向

Sysinternals Suiteをインストール

この先自動起動の設定とか弄るので、それを確認する為に、初期状態を保存できるツールを使う。

実験検証のためにインストール。このVMはインターネット未接続なので、ホストOSでダウンロードする。
https://docs.microsoft.com/en-us/sysinternals/downloads/sysinternals-suite

  • Sysinternals.zipをWin7にコピー、解凍、Autoruns.exeを実行。完全に表示されるまでに数秒かかる。
  • File > Save。出力されたファイルの差分で何が登録されたか確認可能。
PowerShellのアップデート

https://tekunabe.hatenablog.jp/entry/2017/11/10/vagrant_up_error
Vagrant up から進まない!? - Qiita
https://github.com/hashicorp/vagrant/issues/8777

どうも Vagrant 1.9.7 から PowerShell 5.x が必要のようです。 (Windows 7 デフォルトの PowerShell 2ではなく)

とのことなので、アップグレードします。

現状のPowerShellのバージョン。2.0。

C:\Users\IEUser>powershell $PSVersionTable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.5485
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

Win7-KB3191566-x86.zipをダウンロード、VM内にコピー、展開。
管理者として PowerShell を開く。
Install-Wmf5.1.ps1 スクリプトを実行。
再起動。

RemoteManagement有効化

[Linux] Ubuntu 17.10ホストにVagrantを入れてWindowsを動かす - Qiita

PowerShellを管理者権限で開いて、以下を実行する必要あり。

> Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
> winrm quickconfig

だが、

Get-NetConnectionProfile : The term 'Get-NetConnectionProfile' is not recognized as the name of a cmdlet, function
...

とエラーが出る。
Get-NetConnectionProfile not available in Powershell 5.1? - Reddit
どうも、このコマンドはWin8/2012以降にしか無いようだ。

Fixing - WinRM Firewall exception rule not working when Internet Connection Type is set to Public
VagrantでWindows boxを構築する - Qiita
PowerShellでリモートPCの操作を行うに為にEnable-PSRemotingをするための準備 - tech.guitarrapc.cóm

WMF 5.1 のインストールと構成 - MicrosoftDocs

PowerShellには、接続ネットワークがPrivateかWorkgroupの場合に、リモート越しにコマンドを受け取るための機構が備わっています。 ただしデフォルトでは機能が無効になっているため、、外部からのコマンドを受け付けれるように有効にする必要があります。

PS C:\Windows\system32> Enable-PSRemoting
WinRM has been updated to receive requests.
WinRM service type changed successfully.
WinRM service started.

Set-WSManQuickConfig : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113"
Machine="localhost"><f:Message><f:ProviderFault provider="Config provider"
path="%systemroot%\system32\WsmSvc.dll"><f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault"
Code="2150859113" Machine="IE11WIN7"><f:Message>WinRM firewall exception will not work since one of the network
connection types on this machine is set to Public. Change the network connection type to either Domain or Private and
try again. </f:Message></f:WSManFault></f:ProviderFault></f:Message></f:WSManFault>
At line:116 char:17
+                 Set-WSManQuickConfig -force
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Set-WSManQuickConfig], InvalidOperationException
    + FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.

NetworkConnectionTypeを、PublicからDomainかPrivateに変更しなければいけないようだ。

https://www.atmarkit.co.jp/ait/articles/1012/24/news127.html
ローカル・セキュリティ・ポリシー・ツールというもので変更する。

その後、再度実行すると成功した。

PS C:\Windows\system32> Enable-PSRemoting
WinRM is already set up to receive requests on this computer.
WinRM has been updated for remote management.
Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine.
PS C:\Windows\system32>

そのままPowerShell上で実行。

> winrm quickconfig -q
> winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="512"}'
> winrm set winrm/config '@{MaxTimeoutms="1800000"}'
> winrm set winrm/config/service '@{AllowUnencrypted="true"}'
> winrm set winrm/config/service/auth '@{Basic="true"}'
> sc.exe config WinRM start= auto

設定がうまくいけば、以下で3.0と表示される。

> (-Split (( winrm id | where {$_ -like '*ProductVersion*'}) -Split '=')[1])[5]
3.0

6. 立ち上げ直し

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 5985 (guest) => 55985 (host) (adapter 1)
    default: 5986 (guest) => 55986 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: WinRM address: 127.0.0.1:55985
    default: WinRM username: IEUser
    default: WinRM execution_time_limit: PT2H
    default: WinRM transport: negotiate
==> default: Machine booted and ready!
Sorry, don't know how to check guest version of Virtualbox Guest Additions on this platform. Stopping installation.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...

ipconfig
C:\Users\IEUser>ipconfig

Windows IP Configuration


Ethernet adapter Local Area Connection 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::256b:4013:4140:453f%15
   IPv4 Address. . . . . . . . . . . : 10.0.2.15
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.0.2.2

Tunnel adapter isatap.{53152A2F-39F7-458E-BD58-24D17099256A}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

あれ?ふたつ目のネットワークインターフェイスが設定されていないぞ?

VM画面 デバイス->ネットワーク->ネットワーク設定 NATネットワークをホストオンリーアダプターに変更

再びこれを実行すると、とりあえずホストOSから通信は可能になる。


C:\Users\IEUser>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : IE11WIN7
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection 2:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Desktop Adapter
   Physical Address. . . . . . . . . : 08-00-27-99-B1-5F
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::256b:4013:4140:453f%15(Preferred)
   IPv4 Address. . . . . . . . . . . : 172.28.128.3(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Friday, May 03, 2019 2:00:13 AM
   Lease Expires . . . . . . . . . . : Friday, May 03, 2019 2:20:13 AM
   Default Gateway . . . . . . . . . :
   DHCP Server . . . . . . . . . . . : 172.28.128.2
   DHCPv6 IAID . . . . . . . . . . . : 302514215
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1D-92-01-C6-00-15-5D-62-6C-6C

   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter isatap.{53152A2F-39F7-458E-BD58-24D17099256A}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft ISATAP Adapter
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

^C
C:\Users\IEUser>ping 172.28.128.1

Pinging 172.28.128.1 with 32 bytes of data:
Reply from 172.28.128.1: bytes=32 time<1ms TTL=64
Reply from 172.28.128.1: bytes=32 time<1ms TTL=64

Ping statistics for 172.28.128.1:
    Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C
$ ping 172.28.128.2
PING 172.28.128.2 (172.28.128.2) 56(84) bytes of data.
64 bytes from 172.28.128.2: icmp_seq=1 ttl=255 time=0.171 ms
64 bytes from 172.28.128.2: icmp_seq=2 ttl=255 time=0.144 ms
64 bytes from 172.28.128.2: icmp_seq=3 ttl=255 time=0.167 ms
^C
--- 172.28.128.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2052ms
rtt min/avg/max/mdev = 0.144/0.160/0.171/0.018 ms

おわり

ホストオンリーアダプター関係の処理がうまくいっていないが、ひとまずこれでホストOSとゲストOSが通信可能になった。

次は、リバースシェル編。
ハック技術: Windows7ハック #2 バックドアの仕組み(リバースシェル)編 - Qiita

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2