--- title: 環境建置(神作) image: description: --- # 環境建置 ###### tags: `環境建置` `帥氣` `工欲善其事` `必先利其器` * step by step setting ! ## env (Prerequisites)(CTF setting) ```bash= #!/bin/bash # ubuntu18.04 cd $HOME sudo apt-get -y update sudo apt-get -y upgrade sudo apt-get -y install ssh sudo apt-get -y install net-tools sudo apt-get -y install curl sudo apt-get -y install tree sudo apt-get -y install htop sudo apt-get -y install vim sudo apt-get -y install binutils nasm sudo apt-get -y install gcc-multilib g++-multilib sudo apt-get -y install git sudo apt-get -y install libc6-dbg sudo apt-get -y install ruby sudo apt-get -y install nmap sudo apt-get -y install python-pip libssl-dev sudo apt-get -y install gdb sudo apt-get -y install tmux sudo apt-get -y install python sudo apt-get -y install ipython sudo apt-get -y install python3 sudo apt-get -y install ipython3 sudo apt-get -y install python3-pip sudo apt-get -y install python3-dev sudo apt-get -y install clang-format sudo apt-get -y install qemu qemu-system sudo apt autoremove -y sudo apt update && sudo apt upgrade -y sudo gem install one_gadget sudo pip install --upgrade pip sudo pip install --upgrade capstone sudo pip install --upgrade pwntools sudo pip3 install --upgrade git+https://github.com/arthaud/python3-pwntools.git sudo pip install ropgadget #pwndbg git clone https://github.com/pwndbg/pwndbg cd pwndbg ./setup.sh ``` ```bash= #!/bin/bash # ubuntu20.04 cd $HOME sudo apt-get -y update sudo apt-get -y upgrade sudo apt-get -y install ssh sudo apt-get -y install net-tools sudo apt-get -y install curl sudo apt-get -y install vim sudo apt-get -y install binutils nasm sudo apt-get -y install gcc-multilib g++-multilib sudo apt-get -y install git sudo apt-get -y install libc6-dbg sudo apt-get -y install ruby sudo apt-get -y install nmap sudo apt-get -y install python-pip libssl-dev sudo apt-get -y install gdb sudo apt-get -y install tmux sudo apt-get -y install python3 sudo apt-get -y install ipython3 sudo apt-get -y install python3-pip sudo apt-get -y install python3-dev sudo apt-get -y install clang-format sudo apt-get -y install qemu qemu-system sudo apt autoremove -y sudo apt update && sudo apt upgrade -y sudo gem install one_gadget # python3-pwntools include ROPgadget sudo pip3 install --upgrade git+https://github.com/arthaud/python3-pwntools.git #pwndbg git clone https://github.com/pwndbg/pwndbg cd pwndbg ./setup.sh ``` ## ~/.gdbinit ```bash= source ~/pwndbg/gdbinit.py source ~/pwndbg/AutoAttach.py # 自己放 set follow-fork-mode parent set disable-randomization on set disassembly-flavor intel set print pretty define xxd dump binary memory dump.bin $arg0 $arg0+$arg1 shell xxd dump.bin end ``` ## vim ### 好用操作 * [多行註解](https://aben20807.blogspot.com/2017/07/1060701-vim_90.html) ### basic setting ```bash= $ vim ~/.vimrc :set nu :set cursorline :set ai :set bg=dark :set tabstop=4 :set shiftwidth=4 :set expandtab :set encoding=utf-8 :set ttymouse=xterm2 :set mouse=a map <F4> : set nu!<BAR>set nonu?<CR> autocmd FileType make setlocal noexpandtab ``` ### [vundle](https://github.com/VundleVim/Vundle.vim) > Vundle 是一個可以自動下載、安裝與管理 Vim plugins 的工具,讓 Vim 的使用者可以很方便的使用各種 plugins。 1. Set up Vundle: ```bash= $ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim ``` 2. Configure Plugins: ```bash= $ vim ~/.vimrc # 在剛剛的後面,加入以下這些 set nocompatible " be iMproved, required filetype off " required set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'VundleVim/Vundle.vim' Plugin 'tpope/vim-fugitive' Plugin 'git://git.wincent.com/command-t.git' Plugin 'rstacruz/sparkup', {'rtp': 'vim/'} call vundle#end() " required syntax on ``` :::info 之後就能在 call vundle#begin() ~ call vundle#end() 區間加入Plugin ::: 3. Install Plugins: ```bash= $ vim # 執行vim :PluginInstall # 安裝plugin ``` ### [vim-theme (subline)](https://github.com/sickill/vim-monokai) > sublime > [ref](http://wiki.csie.ncku.edu.tw/vim/vimrc) ### [vim-mundo](https://github.com/simnalamburt/vim-mundo) > vim 回復之前所編輯的 1. Set up mundo: ```bash= $ git clone https://github.com/simnalamburt/vim-mundo ~/.vim/bundle/mundo.vim ``` 2. Configure Plugins: ```bash= call vundle#begin() ... Plugin 'simnalamburt/vim-mundo' #加入這行 ... call vundle#end() ``` 3. Install Plugins: ```bash= $ vim # 執行vim :PluginInstall # 安裝plugin ``` 4. Setting vim Config: ```bash= $ mkdir ~/.vim/undo $ vim ~/.vimrc # 加入這三行 set undofile set undodir=~/.vim/undo nnoremap <F5> :MundoToggle<CR> ``` 5. done ![](https://media.giphy.com/media/TGiWBHkQBNk4bxPo49/giphy.gif) :::info 按***F5***即可使用***undotree*** ::: ### [YouCompleteMe](https://github.com/ycm-core/YouCompleteMe) > vim 自動補齊插件 0. Set up: ```bash= $ sudo apt install build-essential cmake python3-dev $ git clone https://github.com/ycm-core/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe $ cd ~/.vim/bundle/YouCompleteMe $ git submodule update --init --recursive $ python3 install.py --clangd-completer $ python3 install.py --all # 出現 go 的 error 是沒關係的 ``` 1. Configure Plugins: ```bash= call vundle#begin() . . . Plugin 'ycm-core/YouCompleteMe' . . . call vundle#end() ``` 2. Install Plugin: ```bash= $ vim :PluginInstall ``` 3. Disable error checking ```bash= $ vim ~/.vimrc let g:ycm_show_diagnostics_ui = 0 set completeopt-=preview ``` ### [auto-pairs](https://github.com/jiangmiao/auto-pairs) > [ref](https://blog.csdn.net/liao20081228/article/details/80347797) 1. Configure Plugins: ```bash= call vundle#begin() . . . Plugin 'jiangmiao/auto-pairs' . . . let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '<':'>'} . . . call vundle#end() ``` 2. Install Plugin: ```bash= $ vim :PluginInstall ``` ### [vim-template](https://github.com/aperezdc/vim-template) * Download ```bash= $ cd ~/.vim/bundle # 如果沒有這個目錄表示你前面沒有裝好 $ git clone git://github.com/aperezdc/vim-template.git ``` * Configure Plugins: ```bash= $ vim ~/.vimrc call vundle#begin() ... Plugin 'aperezdc/vim-template' let g:templates_no_autocmd = 1 ... call vundle#end() ``` > templates_no_autocmd 不關掉的話感覺挺麻煩的(1:disable) * Install Plugin ```bash= $ vim :BundleInstall :help template.txt # 如果成功會有文件可以看 ``` * Setting your Template * 新增自己的樣板 ```bash= $ cd ~/.vim/bundle/vim-template/templates $ vim '=template=.test' test~ # 隨便輸入 :wq ``` * 測試看看 ```bash= $ vim test.py :Template *.test ``` ![](https://media.giphy.com/media/Q9FngeLz0pZlOA17Gt/giphy.gif) ### [tmuxline.vim](https://github.com/edkolev/tmuxline.vim) ### [SimpylFold]() ### [nerdcommenter]() ### [nerdtree]() ### tagbar * 安裝依賴 ```bash= $ sudo apt-get install ctags ``` * 在vundle加入插件 ```bash= # 在.vimrc加入 $ vim ~/.vimrc call vundle#begin() ... "tagbar Plugin 'majutsushi/tagbar' let g:tagbar_ctags_bin = 'ctags' " tagbar 依賴 ctags 外掛 let g:tagbar_width = 30 " 設定 tagbar 的寬度為 30 列,預設 40 列 let g:tagbar_autofocus = 1 " 開啟 tagbar 時游標在 tagbar 頁面內,預設在 vim 開啟的檔案內 let g:tagbar_left = 1 " 讓 tagbar 在頁面左側顯示,預設右邊 "let g:tagbar_sort = 0 " 標籤不排序,預設排序 " <leader>tb 開啟 tagbar 視窗,在左側欄顯示 map <F6> :TagbarToggle<CR> ... call vundle#end() ``` * 安裝 ```bash= $ vim :PluginInstall ``` ## [nerdtree](https://github.com/preservim/nerdtree) ### [markdown-preview.vim](https://github.com/iamcco/markdown-preview.vim/blob/master/README_cn.md) ## oh-my-zsh > 裝B用 ```bash= $ sudo apt-get install zsh $ sudo apt-get install powerline $ sudo apt-get install fonts-powerline $ sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" $ chsh -s /bin/zsh # 使用者登出在登入shell就換了 ``` ### [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions) & [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting) > zsh-autosuggestions : 可以將歷史輸入過的指令提示在後面 > zsh-syntax-highlighting : 當你在輸入 terminal 相關指令時會有提示 ```bash= $ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions $ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting $ vim ~/.zshrc # find plugins (lines 71) plugins=( git extract zsh-autosuggestions zsh-syntax-highlighting ) ``` :::info 重開shell(zsh)就有了 ::: ## tmux > 多工terminal ```bash= $ vim ~/.tmux.conf # General settings --------------------{{{ setw -g mode-keys vi set -g default-terminal "screen-256color" # use 256 colors set -g display-time 400 # status line messages display set -g history-limit 100000 # scrollback buffer n lines set -g mouse on setw -g pane-base-index 1 # Status bar --------------------{{{ set -g status-bg default set -g status-fg default set-option -g status-justify centre set-option -g status-left '#[fg=cyan][#{session_name}]' set-option -g status-left-length 25 set-option -g status-right '#[fg=white,bg=default]%H:%M #[default] #[fg=blue]%Y-%m-%d%a' # window #setw -g automatic-rename off #set-option -g allow-rename off #set-window-option -g window-status-fg brightblue #set-window-option -g window-status-bg default set-window-option -g clock-mode-colour black set-window-option -g clock-mode-style 24 set-window-option -g monitor-activity on set-window-option -g visual-bell off bind-key c new-window -n 'shell' # }}} # panel --------------------{{{ #set-option -g pane-border-fg colour27 #set-option -g pane-active-border-fg colour9 set-option -g display-panes-active-colour blue set-option -g display-panes-colour brightred # }}} ``` ### mouse mode * tmux ```bash $ Ctrl+b + : # 進入tmux cmd $ set -g mouse on # 就可以用滑鼠拉分割畫面大小還有上下滾動,按住 shift 可以回到一般選取字 就可以複製了 ``` * ~/.vimrc ```bash :set ttymouse=xterm2 :set mouse=a # 加入這兩行後可以在vim中用滾輪轉動,vim中選字是virtual mode,要複製vim中文字就案一下y就可以了(virtual mode情況下),當然也可以用tmux的方式按住shift ``` ## git * `commit`方式改成`vim` ```bash= git config --global core.editor vim ``` ## clang-format * `jserv`課程`lab0-c`的`.clang-format` ```bash= BasedOnStyle: Chromium Language: Cpp MaxEmptyLinesToKeep: 3 IndentCaseLabels: false AllowShortIfStatementsOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false AllowShortLoopsOnASingleLine: false DerivePointerAlignment: false PointerAlignment: Right SpaceAfterCStyleCast: true TabWidth: 4 UseTab: Never IndentWidth: 4 BreakBeforeBraces: Linux AccessModifierOffset: -4 ``` ## Make a gif * https://giphy.com/ ## Font [Monaco Font](https://www.google.com/search?q=Monaco+Font&sxsrf=ALeKk01Hl5vmPmxYo7DzRKAWRJUb5R6fyw:1589621929170&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjr96iTi7jpAhVPw4sBHVM0AnAQ_AUoAXoECBEQAw&biw=1920&bih=937#imgrc=lLB2Swk5ASLr4M)被認為是最適合programming的字體,看起來輝常地蘇胡,可參考[這個網站](https://medium.com/@seshumadhav/install-monaco-font-on-ubuntu-670a43814230) 來下載 ![](https://i.imgur.com/NoAk4GA.png) * 方法一 ```bash= $ git clone https://github.com/cstrap/monaco-font $ cd mocano-font $ ./install-font-ubuntu.sh http://www.gringod.com/wp-upload/software/Fonts/Monaco_Linux.ttf $ wget http://www.gringod.com/wp-upload/software/Fonts/Monaco_Linux.ttf $ mkdir ~/.fonts $ cp Monaco_Linux.ttf ~/.fonts/ $ apt update $ apt upgrade $ reboot ``` * 方法二 ```bash= wget http://www.gringod.com/wp-upload/software/Fonts/Monaco_Linux.ttf ``` ![](https://i.imgur.com/lpln7Es.png =80%x) ![](https://i.imgur.com/73bMqTR.png =80%x) 之後打開你的terminal,透過 edit -> reference 就能選到 ***Monaco Regular*** 字體 ## Ref * https://www.mdeditor.tw/pl/pnxU/zh-tw