Share this post on:

环境配置:ubuntu20.04.4 清华源

连续遇到几次optee的pwn题了,正好宋师傅上周与我交流了一番,于是开始了optee学习之路,但是这个搭环境就折磨了我好几天,写一篇博客记录一下

虚拟机走代理

参考另一篇文章,Linux走代理

依赖

sudo apt-get install android-tools-fastboot autoconf bison cscope curl flex gdisk libc6:i386 libfdt-dev libglib2.0-dev libpixman-1-dev libstdc++6:i386 zlib1g:i386 netcat python-crypto uuid-dev xz-utils zlib1g-dev python3-serial

sudo dpkg --add-architecture i386

sudo apt install gcc make vim git expect build-essential linux-headers-uname -r

sudo apt-get install android-tools-adb android-tools-fastboot autoconf automake bc bison build-essential cscope curl device-tree-compiler expect flex ftp-upload gdisk iasl libattr1-dev libc6:i386 libcap-dev libfdt-dev libftdi-dev libglib2.0-dev libhidapi-dev libncurses5-dev libpixman-1-dev libssl-dev libstdc++6:i386 libtool make mtools netcat unzip uuid-dev xdg-utils xterm xz-utils zlib1g-dev zlib* libz1:i386

sudo apt-get install android-tools-adb android-tools-fastboot autoconf automake bc bison build-essential cscope curl device-tree-compiler expect flex ftp-upload gdisk iasl libattr1-dev libc6:i386 libcap-dev libfdt-dev libftdi-dev libglib2.0-dev libattr1-dev libncurses5-dev libpixman-1-dev libssl-dev libstdc++6:i386 libtool libz1:i386 make mtools netcat python-crypto python-serial python-wand unzip uuid-dev xdg-utils xterm xz-utils zliblg-dev 

sudo apt-get install git

由于参考了好几篇文章,不太记得了,所以都用一遍吧(((

下载OPTEE源码

  • 创建存放OPTEE代码的目录
mkdir optee
cd optee
  • git配置

    sudo git config --global user.email "you@example.com"
    sudo git config --global user.name "Your Name"

    填上你的github邮箱和id

  • 使用repo拉取代码(官方文档就这么做的)

    • 下载repo

    因为20.04下不能直接sudo apt install repo了。所以需要我们自己去安装

    这里我们直接去找官方文档安装教程:https://source.android.com/source/downloading?hl=zh-cn

    确保主目录下有一个 bin/ 目录,并且该目录包含在路径中:

    mkdir ~/bin
    PATH=~/bin:$PATH

    下载 Repo 工具,并确保它可执行:

    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    chmod a+x ~/bin/repo
    • 初始化repo
    repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml --repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -b 3.8.0

    这一步我遇到了不少麻烦,不敢保证我这种方法一定没问题了,如果遇到问题了,读着可以参考我放在参考链接里面的几篇文章

    这儿或者后面的repo同步可能遇到一个问题

    此图片的alt属性为空;文件名为image-4.png

    解决:(即将你的默认python版本改为python3)

    sudo apt-get install python-is-python3
    • 修改qemu_v8.mk文件

    修改/optee/.repo/manifests/qemu_v8.mk文件,在每一条project后面添加语句clone-depth=“1”,最后的效果如下

    image-20230511160023909

    • repo同步
    repo sync -j8

安装工具链

  • 手动安装
cd build
sudo make -f toolchain.mk toolchains

这儿由于网速原因可能会失败或很慢很慢,建议手动下载并解压过去

点击链接:https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads/8-3-2019-03

然后在/optee/build/toolchain.mk文件找到对应需要下载的文件,在上面这个链接下载

image-20230511181150072

  • 下载完两个安装包后,将其拷贝到toolchains目录下,并解压(没有这个目录,请手动创建,在build的上一层目录创建)

    sudo mkdir toolchains
    cd toolchains
    sudo mkdir aarch32
    sudo mkdir aarch64
    sudo tar -xvf gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz -C aarch32 --strip-components=1
    sudo tar -xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz -C aarch64 --strip-components=1
  • 然后删除build/toolchain.mk中的下面的行:

    curl -s -L $(2) -o $(TOOLCHAIN_ROOT)/$(3).tar.xz;
  • 再次运行(这儿应该是直接执行完没什么反应)

    sudo make -f toolchain.mk toolchains

编译OPTEE

  • 编译

    sudo make -f qemu_v8.mk all 
  • issue

    • ModuleNotFoundError: No module named ‘Crypto’
    sudo pip3 install pycryptodome
    • ModuleNotFoundError: No module named ‘elftools’
    sudo pip3 install pyelftools
    • ModuleNotFoundError: No module named ‘Cryptodome’
    sudo pip3 install pycryptodomex
    • /bin/sh: line 1: /usr/sbin/iasl: No such file or directory
    wget https://acpica.org/sites/acpica/files/acpica-unix-20191018.tar.gz
    tar zxvf acpica-unix-20191018.tar.gz
    cd acpica-unix-20191018
    sudo make clean && make iasl
    sudo cp ./generate/unix/bin/iasl /usr/sbin/
    • fatal error: openssl/sha.h: No such file or directory
    sudo apt-get install libssl-dev
    • you should not run configure as root

    这个问题就在make的时候加一句话即可

    sudo make FORCE_UNSAFE_CONFIGURE=1 -f qemu_v8.mk all 

    到这儿OPTEE就应该已经成功编译完成了

启动qemu

cd build       //切换到build目录  
make -f qemu_v8.mk run-only       //启动qemu v8并运行OP-TEE 

在qemu界面中输入字母“c”回车之后,就会启动两个terminal,一个是normal world的terminal,另外一个是secure world的terminal

参考文章

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads/8-3-2019-03

https://blog.csdn.net/capodexi/article/details/123548850

https://blog.csdn.net/qq_24573573/article/details/119454841?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-119454841-blog-123548850.235^v35^pc_relevant_anti_vip&spm=1001.2101.3001.4242.2&utm_relevant_index=2

https://blog.csdn.net/rjszz1314/article/details/114637638?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~Rate-1-114637638-blog-124156005.pc_relevant_aa&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2~default~CTRLIST~Rate-1-114637638-blog-124156005.pc_relevant_aa&utm_relevant_index=1

https://blog.csdn.net/yuxi_xi/article/details/128905197?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-128905197-blog-123548850.235^v33^pc_relevant_default_base&spm=1001.2101.3001.4242.2&utm_relevant_index=4

https://source.android.com/source/downloading?hl=zh-cn

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

Share this post on:

Leave a Comment

您的邮箱地址不会被公开。 必填项已用 * 标注