首页 > 其他分享 >路由器固件模拟环境搭建

路由器固件模拟环境搭建

时间:2024-01-22 17:13:56浏览次数:34  
标签:git -- dev echo CANDIDATES install 固件 路由器 搭建

路由器固件模拟环境搭建

binwalk

安装参考

参考链接
https://xz.aliyun.com/t/5697?time__1311=n4%2BxnD07Dti%3D0%3DDk8GCDlhjm5fcQQeiKN4D&alichlgref=https%3A%2F%2Fwww.google.com%2F

http://zeroisone.cc/2018/03/20/固件模拟调试环境搭建/

但是他们都有一个问题,在按他们的步骤完成的情况下,binwalk提取文件系统时出现 sasquatch报错。

解决方法

从https://github.com/attify/firmware-analysis-toolkit 这个FAT工具里提取出setup.sh,里面的binwalk安装方式正是我们想要的

sudo apt update
sudo apt install -y python3-pip python3-pexpect unzip busybox-static fakeroot kpartx snmp uml-utilities util-linux vlan qemu-system-arm qemu-system-mips qemu-system-x86 qemu-utils wget tar

git clone --depth=1 https://github.com/ReFirmLabs/binwalk.git
cd binwalk

# Temporary fix for sasquatch failing to install (From https://github.com/ReFirmLabs/binwalk/pull/601) 这一步修复sasquatch报错
sed -i 's;\$SUDO ./build.sh;wget https://github.com/devttys0/sasquatch/pull/47.patch \&\& patch -p1 < 47.patch \&\& \$SUDO ./build.sh;' deps.sh

# Change to python3 in deps.sh to allow installation on Ubuntu 20.04 (binwalk commit 2b78673)
sed -i '/REQUIRED_UTILS="wget tar python"/c\REQUIRED_UTILS="wget tar python3"' deps.sh
sudo ./deps.sh --yes
sudo python3 ./setup.py install
sudo -H pip3 install git+https://github.com/ahupp/python-magic
sudo -H pip3 install git+https://github.com/sviehb/jefferson

同时,如果你在虚拟机中无法git clone出现网络错误中断安装,记得在每个wget、git clone前加上proxychain4,这种代理工具的使用不多赘述

deps.sh

#!/bin/bash

# Check for the --yes command line argument to skip yes/no prompts
if [ "$1" = "--yes" ]
then
    YES=1
else
    YES=0
fi

set -eu
set -o nounset
set -x

if ! which lsb_release > /dev/null
then
    function lsb_release {
        if [ -f /etc/os-release ]
        then
            [[ "$1" = "-i" ]] && cat /etc/os-release | grep ^"ID" | cut -d= -f 2
            [[ "$1" = "-r" ]] && cat /etc/os-release | grep "VERSION_ID" | cut -d= -d'"' -f 2
        elif [ -f /etc/lsb-release ]
        then
            [[ "$1" = "-i" ]] && cat /etc/lsb-release | grep "DISTRIB_ID" | cut -d= -f 2
            [[ "$1" = "-r" ]] && cat /etc/lsb-release | grep "DISTRIB_RELEASE" | cut -d= -f 2
        else
            echo Unknown
        fi
    }
fi

if [ $YES -eq 0 ]
then
    distro="${1:-$(lsb_release -i|cut -f 2)}"
    distro_version="${1:-$(lsb_release -r|cut -f 2|cut -c1-2)}"
else
    distro="${2:-$(lsb_release -i|cut -f 2)}"
    distro_version="${2:-$(lsb_release -r|cut -f 2|cut -c1-2)}"
fi
REQUIRED_UTILS="wget tar python3"
APTCMD="apt"
APTGETCMD="apt-get"
YUMCMD="yum"
if [ $distro = "Kali" ]
then
    APT_CANDIDATES="git locales build-essential qt5base-dev mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract util-linux firmware-mod-kit cramfsswap squashfs-tools zlib1g-dev liblzma-dev liblzo2-dev sleuthkit default-jdk lzop cpio"
elif [ $distro_version = "14" ]
then
    APT_CANDIDATES="git locales build-essential libqt4-opengl mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract cramfsprogs cramfsswap squashfs-tools zlib1g-dev liblzma-dev liblzo2-dev sleuthkit default-jdk lzop srecord cpio"
elif [ $distro_version = "15" ]
then
    APT_CANDIDATES="git locales build-essential libqt4-opengl mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract cramfsprogs cramfsswap squashfs-tools zlib1g-dev liblzma-dev liblzo2-dev sleuthkit default-jdk lzop srecord cpio"
elif [ $distro_version = "16" ]
then
    APT_CANDIDATES="git locales build-essential libqt4-opengl mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract cramfsprogs cramfsswap squashfs-tools zlib1g-dev liblzma-dev liblzo2-dev sleuthkit default-jdk lzop srecord cpio"
elif [ $distro_version = "18" ]
then
    APT_CANDIDATES="git locales build-essential libqt4-opengl mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract cramfsswap squashfs-tools zlib1g-dev liblzma-dev liblzo2-dev sleuthkit default-jdk lzop srecord cpio"
else
    APT_CANDIDATES="git locales build-essential qtbase5-dev mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract cramfsswap squashfs-tools zlib1g-dev liblzma-dev liblzo2-dev sleuthkit default-jdk lzop srecord cpio"
fi
PYTHON3_APT_CANDIDATES=""
PYTHON3_YUM_CANDIDATES=""
YUM_CANDIDATES="git gcc gcc-c++ make openssl-devel qtwebkit-devel qt-devel gzip bzip2 tar arj p7zip p7zip-plugins cabextract squashfs-tools zlib zlib-devel lzo lzo-devel xz xz-compat-libs xz-libs xz-devel xz-lzma-compat python-backports-lzma lzip pyliblzma perl-Compress-Raw-Lzma lzop srecord"
PYTHON="$(which python3)"

# Check for root privileges
if [ $UID -eq 0 ]
then
    echo "UID is 0, sudo not required"
    SUDO=""
else
    SUDO="sudo -E"
    REQUIRED_UTILS="sudo $REQUIRED_UTILS"
fi

function install_yaffshiv
{
    proxychains4 git clone --quiet --depth 1 --branch "master" https://github.com/devttys0/yaffshiv
    (cd yaffshiv && $SUDO $PYTHON setup.py install)
    $SUDO rm -rf yaffshiv
}

function install_sasquatch  #关键修改处
{
    #proxychains4 git clone --quiet --depth 1 --branch "master" https://github.com/devttys0/sasquatch
    (cd sasquatch && proxychains4 wget https://github.com/devttys0/sasquatch/pull/47.patch && patch -p1 < 47.patch && $SUDO ./build.sh)
    $SUDO rm -rf sasquatch
}

function install_jefferson
{
    proxychains4 git clone --quiet --depth 1 --branch "master" https://github.com/sviehb/jefferson
    (cd jefferson && $SUDO $PYTHON -mpip install -r requirements.txt && $SUDO $PYTHON setup.py install)
    $SUDO rm -rf jefferson
}

function install_cramfstools
{
  # Downloads cramfs tools from sourceforge and installs them to $INSTALL_LOCATION
  TIME=`date +%s`
  INSTALL_LOCATION=/usr/local/bin

  # https://github.com/torvalds/linux/blob/master/fs/cramfs/README#L106
  git clone --quiet --depth 1 --branch "master" https://github.com/npitre/cramfs-tools
  # There is no "make install"
  (cd cramfs-tools \
  && make \
  && $SUDO install mkcramfs $INSTALL_LOCATION \
  && $SUDO install cramfsck $INSTALL_LOCATION)

  rm -rf cramfs-tools
}


function install_ubireader
{
    proxychains4 git clone --quiet --depth 1 --branch "master" https://github.com/jrspruitt/ubi_reader
    (cd ubi_reader && $SUDO $PYTHON setup.py install)
    $SUDO rm -rf ubi_reader
}

function install_pip_package
{
    PACKAGE="$1"
    $SUDO $PYTHON -mpip install $PACKAGE
}

function find_path
{
    FILE_NAME="$1"

    echo -ne "checking for $FILE_NAME..."
    which $FILE_NAME > /dev/null
    if [ $? -eq 0 ]
    then
        echo "yes"
        return 0
    else
        echo "no"
        return 1
    fi
}

# Make sure the user really wants to do this
if [ $YES -eq 0 ]
then
    echo ""
    echo "WARNING: This script will download and install all required and optional dependencies for binwalk."
    echo "         This script has only been tested on, and is only intended for, Debian based systems."
    echo "         Some dependencies are downloaded via unsecure (HTTP) protocols."
    echo "         This script requires internet access."
    echo "         This script requires root privileges."
    echo ""
    if [ $distro != Unknown ]
    then
        echo "         $distro $distro_version detected"
    else
        echo "WARNING: Distro not detected, using package-manager defaults"
    fi
    echo ""
    echo -n "Continue [y/N]? "
    read YN
    if [ "$(echo "$YN" | grep -i -e 'y' -e 'yes')" == "" ]
    then
        echo "Quitting..."
        exit 1
    fi
elif [ $distro != Unknown ]
then
     echo "$distro $distro_version detected"
else
    echo "WARNING: Distro not detected, using package-manager defaults"
fi

# Check to make sure we have all the required utilities installed
NEEDED_UTILS=""
for UTIL in $REQUIRED_UTILS
do
    find_path $UTIL
    if [ $? -eq 1 ]
    then
        NEEDED_UTILS="$NEEDED_UTILS $UTIL"
    fi
done

# Check for supported package managers and set the PKG_* envars appropriately
find_path $APTCMD
if [ $? -eq 1 ]
then
    find_path $APTGETCMD
    if [ $? -eq 1 ]
    then
        find_path $YUMCMD
        if [ $? -eq 1 ]
        then
            NEEDED_UTILS="$NEEDED_UTILS $APTCMD/$APTGETCMD/$YUMCMD"
        else
            PKGCMD="$YUMCMD"
            PKGCMD_OPTS="-y install"
            PKG_CANDIDATES="$YUM_CANDIDATES"
            PKG_PYTHON3_CANDIDATES="$PYTHON3_YUM_CANDIDATES"
        fi
    else
        PKGCMD="$APTGETCMD"
        PKGCMD_OPTS="install -y"
        PKG_CANDIDATES="$APT_CANDIDATES"
        PKG_PYTHON3_CANDIDATES="$PYTHON3_APT_CANDIDATES"
    fi
else
    if "$APTCMD" install -s -y dpkg > /dev/null
    then
        PKGCMD="$APTCMD"
        PKGCMD_OPTS="install -y"
        PKG_CANDIDATES="$APT_CANDIDATES"
        PKG_PYTHON3_CANDIDATES="$PYTHON3_APT_CANDIDATES"
    else
        PKGCMD="$APTGETCMD"
        PKGCMD_OPTS="install -y"
        PKG_CANDIDATES="$APT_CANDIDATES"
        PKG_PYTHON3_CANDIDATES="$PYTHON3_APT_CANDIDATES"
    fi
fi

if [ "$NEEDED_UTILS" != "" ]
then
    echo "Please install the following required utilities: $NEEDED_UTILS"
    exit 1
fi

# Do the install(s)
cd /tmp
$SUDO $PKGCMD $PKGCMD_OPTS $PKG_CANDIDATES
if [ $? -ne 0 ]
    then
    echo "Package installation failed: $PKG_CANDIDATES"
    exit 1
fi
install_pip_package "setuptools matplotlib capstone pycryptodome gnupg tk"
install_sasquatch
install_yaffshiv
install_jefferson
#install_ubireader

if [ $distro_version = "18" ]
then
install_cramfstools
fi

经过安装install_ubireader这个sh的function可以禁用,因为这个直接用他sh里的安装会出现git clone错误

以下是ubi_reader的安装代替

//安装依赖
$ sudo apt-get install liblzo2-dev
$ sudo pip install python-lzo
//安装ubi_reader
$ sudo pip install ubi_reader

标签:git,--,dev,echo,CANDIDATES,install,固件,路由器,搭建
From: https://www.cnblogs.com/brain-Z/p/17980446

相关文章

  • CUAV飞行控制器使用固件说明
    一般无人机飞控硬件支持ArduPloit和PX4固件认识ArduPilotArduPilot是一种灵活、可扩展、高性能的自动驾驶软件系统,支持多种载具类型和任务类型,例如无人机、车辆、船只、固定翼飞机、多旋翼飞行器等。ArduPilot固件可在各种不同的硬件上工作,其中包含Pixhawk系列和CUAV系列。Ardu......
  • SQL Server 复制(Replication) ——事务复制搭建
    本文演示如何搭建最基本的事务复制。环境准备:虚拟机2台:服务器名分别为RepA和RepB,RepA为发布服务器,RepB为订阅服务器。均安装WindowsServer2008R2英文版(在外企工作的原因)。并确保两台服务器能互访。SQLServer:在上面的虚拟机中分别安装SQLServer2008R2x64英文企业版。演示数据......
  • QT笔记:搭建环境
    QT笔记:搭建环境QT安装下载​ 安装地址https://www.qt.io/download,QT分为商业版和社区版,商业版收费,社区版不收费但禁止商用。个人使用直接下装社区版就好了,下载需要提交个人邮箱并进行注册。安装QT6QT版本QT目前最新版本为QT6,选择安装最新的稳定版本即可。IDEQT有配套的代......
  • 智慧能源矿产解决方案:搭建遍布全球的数字仪表信息监控、环境传感数据监测
    解决方案:成功将厂区汽机房、电控楼、主变、机力塔等重要部位纳入集中监控系统,实现远端移动监控,满足客户项目需求,提升厂区安全等级;实现主要设备指数及告警远程抄录,提高工作效率,降低人力成本 智慧能源矿产解决方案借助全球网络与计算资源能力,中国联通国际可为能源行业客户搭......
  • 手把手教你怎么搭建属于自己的服务器(保姆级教程)
    最近总是想搭建自己的网站,奈何皮夹里空空如也,服务器也租不起,更别说域名了。于是我就寻思能否自己搭建个服务器,还不要钱呢?还真行!!!有两个免费的建站工具:Apache和Nginx由于两个工具建站方法差不多,所以我就以Nginx为例1.安装Nginx首先前往Nginx官网(nginx.org[1])进行下载,也可以......
  • 从零搭建完整python自动化测试框架(UI自动化和接口自动化 )
    从零搭建完整python自动化测试框架(UI自动化和接口自动化)本自动化测试框架采用python+unittest的基础来搭建,采用PO模式、数据驱动的思想,通过selenium来实现WEBUI自动化,通过request来实现接口自动化。移动终端的自动化也可在该框架基础上去构建补充。 总体框架总体框架......
  • 基于pytest搭建接口自动化测试框架,提供源码
     基于pytest搭建接口自动化测试框架 框架整体介绍和方法教程第三代框架使用教程,该框架比第二代这个完善了很多https://blog.csdn.net/aaaaaaaaanjjj/article/details/129597973新框架(第二代比这个功能多了很多,用例使用yaml编写)pytest+yaml设计接口自动化框架过程记录......
  • 基于taro搭建小程序多项目框架
    前言为什么需要这样一个框架,以及这个框架带来的好处是什么?从字面意思上理解:该框架可以用来同时管理多个小程序,并且可以抽离公用组件或业务逻辑供各个小程序使用。当你工作中面临这种同时维护多个小程序的业务场景时,可以考虑使用这种模式。灵感来自最近webpack的多项目打包构建......
  • 5G穿墙王!TP-LINK发布BE5100 Wi-Fi 7路由器:2.5G网口 279元
    1月14日消息,日前,TP-LINK发布BE5100Wi-Fi7路由器,到手价279元,支持MLO、4KQAM、MRU、前导打孔等Wi-Fi7新特性。据介绍,在MLO多链路技术加持下,2.4G+5G叠加快至7.3倍,4KQAM高阶调制,速率提升至120%。MRU技术允许将多个资源块分配给单个用户,提升传输效率,降低延迟。TP-LINKBE5100还是“......
  • 在WSL2下的Ubuntu中搭建android开发环境
    关闭虚拟机wsl--shutdown 查看虚拟机是否已经关闭wsl--list--running 在Win11下开启嵌套的VMnotepad%USERPROFILE%\.wslconfig.txt[wsl2]nestedVirtualization=true 安装JDK并配置环境变量sudoaptinstallopenjdk-17-jdk-y vi~/.profileexportJAVA_HOME=......