日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Firmadyne固件模拟路由器环境搭建

發布時間:2024/3/24 编程问答 76 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Firmadyne固件模拟路由器环境搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

0x01 前言

本文介紹了在對固件進行分析的環境準備部分,主要是對Firmadyne這個工具的環境搭建,最后搭建完用Netgear的路由器固件進行測試。

安裝完后測試了一下,在我測試的幾個固件中(Tenda路由器,Cisco交換機、防火墻、路由器,D-Link路由器),目前只能運行大部分的路由器的固件,交換機和防火墻的固件都運行不起來。

Firmadyne是一款自動化分析嵌入式Linux系統安全的開源軟件,由卡內基梅隆大學的Daming D. Chen開發完成的。它支持批量檢測,整個系統包括固件的爬取、root文件系統的提取、QEMU模擬執行以及漏洞的挖掘。

實驗環境及需要的工具:

  • 系統:Ubuntu14.04
    • 在Kali最新版和Ubuntu16.04LTS上都會有奇奇怪怪的問題,后來在issue中找到作者的實驗環境為Ubuntu14.04
    • 下載:http://mirrors.ustc.edu.cn/ubuntu-releases/14.04/
  • 工具:
    • Firmadyne
      • 項目地址:https://github.com/firmadyne/firmadyne
      • README.md中有詳細的配置和安裝步驟
    • Firmware Analysis Toolkit
      • 項目地址:https://github.com/attify/firmware-analysis-toolkit
      • 該工具集包含了binwalk、Firmadyne等必須的工具。這里我們只需要克隆該倉庫到本地即可
    • qemu
      • 可以直接用apt-get安裝,只安裝一部分
      • 也可以從github的倉庫編譯安裝所有的模塊

0x02 環境配置

2.1 克隆Firmware Analysis Toolkit工具集倉庫

# 1. 安裝依賴 sudo apt-get install busybox-static fakeroot git dmsetup kpartx netcat-openbsd nmap python-psycopg2 python3-psycopg2 snmp uml-utilities util-linux vlan# 2. clone git clone --recursive https://github.com/attify/firmware-analysis-toolkit.git

2.2 安裝binwalk

# 1. 安裝依賴和binwalk cd firmware-analysis-toolkit/binwalk sudo ./deps.sh sudo python setup.py install# 2. 對于 python2.x,還需要安裝以下的庫 sudo -H pip install git+https://github.com/ahupp/python-magic sudo -H pip install git+https://github.com/sviehb/jefferson

測試是否安裝成功:

hzy@ubuntu:~$ binwalk Binwalk v2.1.2-c036535 Craig Heffner, ReFirmLabs https://github.com/ReFirmLabs/binwalkUsage: binwalk [OPTIONS] [FILE1] [FILE2] [FILE3] ...Disassembly Scan Options:-Y, --disasm Identify the CPU architecture of a file using the capstone disassembler... ...-s, --status=<int> Enable the status server on the specified porthzy@ubuntu:~$

2.3 安裝Firmadyne

? ? ?1、進入Firmadyne目錄,然后打開firmadyne.config,修改 FIRMWARE_DIR的路徑為當前Firmadyne目錄的絕對路徑

cd firmware-analysis-toolkit/firmadynevim firmadyne.config# 以下為firmadyne.config中的內容 #!/bin/sh# uncomment and specify full path to FIRMADYNE repository FIRMWARE_DIR=/home/hzy/firmware-analysis-toolkit/firmadyne/# specify full paths to other directories BINARY_DIR=${FIRMWARE_DIR}/binaries/ TARBALL_DIR=${FIRMWARE_DIR}/images/ SCRATCH_DIR=${FIRMWARE_DIR}/scratch/ SCRIPT_DIR=${FIRMWARE_DIR}/scripts/# functions to safely compute other paths... ... ————————————————

? ? 2、安裝Firmadyne

sh ./download.sh

2.4 安裝postgresql數據庫

sudo apt-get install postgresql# 用戶的密碼設置為:firmadyne sudo -u postgres createuser -P firmadyne, with password firmadynesudo -u postgres createdb -O firmadyne firmware# 注意這里的數據庫文件是在firmadyne/目錄下,也就是該命令要在根目錄firmware-analysis-toolkit/目錄下執行 sudo -u postgres psql -d firmware < ./firmadyne/database/schema

啟動postgresql數據庫,確認其正在運行。

  • 這里我在kali測試的時候,如果沒有先啟動數據庫,就進行添加用戶的命令會報錯。
  • 還遇到了一個問題,明明數據庫服務在運行,但是添加用戶的時候一直報的錯也是服務沒有運行的錯,這種情況下我是直接重裝了一遍postgresql
  • 具體出現的錯大家可以在網上搜索解決方案即可。一般還是有現成的方法的。
sudo service postgresql startsudo service postgresql status

2.5 安裝qemu

QEMU是一套由法布里斯·貝拉(Fabrice Bellard)所編寫的以GPL許可證分發源碼的模擬處理器,在GNU/Linux平臺上使用廣泛。

這里有兩種安裝方法:

  • 直接通過apt-get安裝
sudo apt-get install qemu-system-arm qemu-system-mips qemu-system-x86 qemu-utils
  • 編譯安裝
git clone git://git.qemu.org/qemu.git cd qemu git submodule init git submodule update --recursive apt install libglib2.0 libglib2.0-dev apt install autoconf automake libtool ./configure make make install

在執行命令./configure以后可能會報錯:

ERROR: pixman >= 0.21.8 not present.Please install the pixman devel package.

可以通過執行命令:apt-get install libpixman-1-dev解決

0x03 測試運行

? ? 1、將firmware-analysis-toolkit/目錄下的fat.py和reset.py移動到firmadyne/目錄下:

mv fat.py ./firmadyne mv reset.py ./firmadyne

? ? 2、修改fat.py中的執行權限、firmadyne的路徑firmadyne_path以及root密碼root_pass

chmod +x fat.pyvim fat.py # 以下是fat.py中的內容#!/usr/bin/env python2.7import os import pexpect import sys# Put this script in the firmadyne path downloadable from # https://github.com/firmadyne/firmadyne#Configurations - change this according to your system firmadyne_path = "/home/hzy/firmware-analysis-toolkit/firmadyne" binwalk_path = "/usr/local/bin/binwalk" root_pass = "123456" firmadyne_pass = "firmadyne"... ...

? ? 3、下載要模擬的路由器固件

? ? 要模擬的路由器為:WNAP320

? ? 在https://www.netgear.com/support/product/WNAP320.aspx#Firmware%20Version%203.7.11.4中下載固件文件

? ? 假設我這里將固件文件重命名為 netgear.zip,并放在/home/hzy/firmware/目錄下
?

? ? 4、測試運行

hzy@ubuntu:~/firmware-analysis-toolkit/firmadyne$ sudo ./fat.py [sudo] password for hzy: __ _ / _| | | | |_ __ _ | |_ | _| / _` | | __|| | | (_| | | |_ |_| \__,_| \__| Welcome to the Firmware Analysis Toolkit - v0.2Offensive IoT Exploitation Training - http://offensiveiotexploitation.comBy Attify - https://attify.com | @attifyme[?] Enter the name or absolute path of the firmware you want to analyse : /home/hzy/firmware/netgear.zip [?] Enter the brand of the firmware : Netgear [+] Now going to extract the firmware. Hold on.. [+] Firmware : /home/hzy/firmware/netgear.zip [+] Brand : Netgear [+] Database image ID : 2 [+] Identifying architecture [+] Architecture : mipseb [+] Storing filesystem in database [!] Filesystem already exists [+] Building QEMU disk image [+] Setting up the network connection, please standby [+] Network interfaces : [('brtrunk', '192.168.0.100')] [+] Running the firmware finally [+] command line : sudo /home/hzy/firmware-analysis-toolkit/firmadyne/scratch/2/run.sh [*] Press ENTER to run the firmware...

[+] Network interfaces : [('brtrunk', '192.168.0.100')]可以看到,啟動了一個服務,可以通過192.168.0.100訪問

接下里按Enter鍵運行該固件,等運行完了以后就可以從瀏覽器訪問了:

0x04 總結

主要還是參考了參考資料1,但是中間踩了很多坑,可以查閱參考資料3。

這個firmadyne還有其他的用法,可以參考下參考資料2。

0x05 參考資料

  • 物聯網設備的固件模擬環境搭建
  • 嵌入式Linux固件模擬與安全分析系統Firmadyne交流
  • Error:Traceback.
  • 總結

    以上是生活随笔為你收集整理的Firmadyne固件模拟路由器环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。