LoginSignup
0
0

More than 1 year has passed since last update.

バッファオーバーフロー勉強環境の構築

Last updated at Posted at 2021-05-10

自宅の Intel Celeron メモリ4GB Windows 10 の限界にチャレンジ

WSL の ubuntu では動かない pwn がある
VirtualBox に kali があるが, python2 の pwn が使えない

なので,VirtualBox に新しく Ubuntu を作ることにした。

至難の業 VirtualBox に Ubuntu を入れる

貧乏なので自宅のパソコンは,Intel Celeron メモリ4GB の Windows 10だ。
自慢ではないが,給料が安いので,PCの予算は5万円以下だった。
もう一度言う
給料が安いので,仕方がない。
DELL製だが,DELLの怪しげなプレインストールアプリを全部消すというチューニングはしてある。
この我が愛機,低スペックすぎて,VirtualBox に Ubuntu を入れるのも至難の業だった。
結論から言うと,

から落としてきたISOが一番,軽量だったのか,かろうじてインストールできた。

Ubuntu Desktop 日本語 Remixのダウンロードのううち,
Ubuntu 18.04.3 LTSが
インストールできた。

ここで得た重要な知見

isoは Ubuntu Desktop 日本語 Remix の Ubuntu 18.04.3 LTS を使え

ubuntu本家のサイトはダウンロードが遅い
ubuntu本家のISOは低スペックマシンの VirtualBox にはインストールできない。

メモリは4G中 1536MBをUbuntuに与える(インストール時)
メモリは4G中 1024MBをUbuntuに与える(通常時)

インストール中に画面が真っ暗になって,数分以内に回復しなければ,最初からやり直すべし。

画面が真っ黒でもディスクランプに赤や青のランプが点灯して,何かやっているように見えるが,1日待っても2日待っても先に進まない。
image.png

最小構成でインストールし,インストール中にupdateしないを選択

makeやperlが入ってないけど,使わないofficeを入れる時間を待つよりまし。

自動アップデート無効

$ cat /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

$ cat /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";

Guest Additions のインストール

画面のサイズが自由自在になるやつ

sudo apt update
sudo apt-get update
sudo apt upgrade
sudo apt install gcc
sudo apt install make
sudo apt install perl

gcc make perl を入れたら Guest Additions CD イメージの挿入

文字を大きく,vim

Settings > Universal Access > Large Text
sudo apt install vim

python2.7 等のインストール

sudo apt install gdb
sudo apt install python2.7
sudo apt install python-pip
sudo apt install python-dev
sudo apt install git
sudo apt install libssl-dev
sudo apt install libffi-dev
sudo apt install build-essential

pwntools 等のインストール

sudo pip install pip
sudo pip install pwntools
sudo pip install pwn
sudo pip install pathlib2

英語に戻す

sudo update-locale LANG=en_US.UTF8

gdb-peda のインストール

git clone https://github.com/longld/peda.git ~/peda
echo "source ~/peda/peda.py" >> ~/.gdbinit

checksec のインストール

git clone https://github.com/slimm609/checksec.sh

rp++ のインストール

wget https://github.com/downloads/0vercl0k/rp/rp-lin-x64

Pwngdb のインストール

cd ~/
git clone https://github.com/scwuaptx/Pwngdb.git 
cp ~/Pwngdb/.gdbinit ~/

ヒープが作成されない状態だとエラーになるが,インストール失敗ではない

gdb-peda$ heapinfo
Python Exception <class 'gdb.MemoryError'> Cannot access memory at address 0x0: 
Python Exception <class 'gdb.error'> Error occurred in Python command: Cannot access memory at address 0x0: 
Error occurred in Python command: Error occurred in Python command: Cannot access memory at address 0x0

プロンプトを短くする

Windowsのデスクトップと共有フォルダを作って,そこでpwnをするので,rootのプロンプトを短くする
# のプロンプトが出ている状態で,

# vi ~/.bashrc

if [ "$color_prompt" = yes ]; then をさがして,編集する。

編集後

if [ "$color_prompt" = yes ]; then
#    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
     PS1='${debian_chroot:+($debian_chroot)}\[\033[00m\]\$ '
else
#    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
     PS1='${debian_chroot:+($debian_chroot)}\$ '
fi

これだとshellを奪ったときのプロンプトと似てるのでカレントディレクトリは表示した方がいいかも?

if [ "$color_prompt" = yes ]; then
#    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
     PS1='${debian_chroot:+($debian_chroot)}\[\033[00m\]\w\$ '
else
#    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
     PS1='${debian_chroot:+($debian_chroot)}\w\$ '
fi

gmpy2 のインストール

これは CTF で small e RSA 問題を解くときに必須

sudo apt-get update
sudo apt-get install python3-gmpy2

angr のインストール

CTF で定番なので,食わず嫌いせず,チャレンジ
最も重要なのは,仮想環境にインストールし,バッファオーバーフロー勉強環境を壊さないこと。
angrの公式ページで「共有ライブラリを上書きしてangrをインストールした場合に生じる問題には責任をとらない。」と断言しています。

sudo apt update
sudo apt-get update
sudo apt upgrade
sudo apt autoremove
仮想マシンのスナップショット作成

仮想環境の構築

$ sudo apt-get install python3-dev libffi-dev build-essential virtualenvwrapper
ターミナルを再起動
# にangr環境を作る
# mkvirtualenv --python=$(which python3) angr
...
(angr) ~#   <--- プロンプトに仮想環境名の angr が表示されたらok

仮想環境 angr に入るとき

~# workon angr
(angr) ~#

仮想環境 angr から抜けるとき

(angr) ~# deactivate
~# 

仮想環境 angr に angr を入れる

~# workon angr
(angr) ~#         <--- プロンプトをよく確認すること
(angr) ~# pip install angr

binwalk のインストール

binwalkはpython3.6以上のみサポート

~# wget https://github.com/ReFirmLabs/binwalk/archive/refs/heads/master.zip
~# unzip master.zip
~# cd binwalk-master
~/binwalk-master# sudo python3 setup.py install
~/binwalk-master# binwalk

Binwalk v2.2.1

32ビットELF対応

$ sudo dpkg --add-architecture i386
$ sudo apt-get update
$ sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
$ sudo apt-get install multiarch-support
0
0
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
0
0