# 109 物聯網作業系統攻擊介紹與實務操作1 (11/25) [toc] ## Kali Linux 無法複製、貼上 ```shell # 安裝VM Tools apt-get install open-vm-tools-desktop # 重新啟動服務 systemctl restart vmware-tools ``` ## 虛擬機帳密 ``` Metasploitable2 account: msfadmin password: msfadmin Kali Linux account: root password: toor ``` 兩台網路都設定在 NAT 模式 ## Demo 1 使用 Python 內建函式庫進行編碼轉換 ```python= # ASCII to binary >>> import binascii >>> bin(int(binascii.hexlify('hello'), 16)) # Binary to ASCII >>> n = int('0b110100001100101011011000110110001101111', 2) >>> binascii.unhexlify('%x' % n) ``` ## 練習 1 算出 16 進位的 41414141 轉換為 ASCII 是甚麼字串 ```python= >>> binascii.unhexlify("0x41414141") ``` ## Demo 2 在像是Ubuntu, Arch Linux之類部分主流的Linux作業系統中辨識系統為大端還是小端: ```bash $ lscpu ``` 在功能跟指令被砍掉大半的嵌入式系統內,我們可以直接尋找作業系統上的執行檔,針對他們下file的指令: ```bash $ file {Binary_file} ELF 64-bit LSB shared object, x86-64, version 1 (SYSV) ``` ## 練習 2 找到家目錄底下的使用者(root)設定檔資料夾 (.config) 並將其下任一資料夾複製到 /tmp目錄底下 ```bash= $ ls -al ~ $ cd .config $ cp -r [Folder Name] /tmp ``` ## Demo 3 若目前使用者為 root,新增一個一般使用者權限的帳號 test ```bash= $ useradd test $ passwd test $ su test $ id ``` 檢視密碼檔 /etc/shadow 的權限,並嘗試利用 test 帳號列舉其檔案內容 ```bash= $ ls -l /etc/shadow $ cat /etc/shadow ``` 於終端機開新分頁 (Ctrl+Shift+T) 並使用 root 帳號替 xxd 啟用 SUID ```bash= $ which xxd $ chmod u+s /usr/bin/xxd $ ls -l /usr/bin/xxd ``` 透過下列指令,我們透過 xxd 將 /etc/shadow 轉為16 進位後再恢復並輸出 ```bash= $ xxd "/etc/shadow" | xxd -r ``` ## 練習 3 模擬攻擊者在未知的條件下用 find 指令尋找系統上具有 SUID 的執行檔 ```bash= $ find / -perm -u=s -type f 2>/dev/null ``` ## 練習 4 於 /tmp 目錄底下新增一檔案並將其權限設定為所有使用者皆可讀、寫與執行 ```bash= $ touch /tmp/test1 $ ls -l /tmp/test1 $ chmod 777 /tmp/test1 $ ls -l /tmp/test1 ``` 切換至一般使用者帳號 test 並嘗試刪除該檔案 ```bash= $ su test $ ls -l test1 $ rm test1 ```