ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Kernel environment construction(Kernel环境搭建)

2022-05-03 00:01:52  阅读:247  来源: 互联网

标签:tmp Kernel make sudo sh environment construction scripts rootfs


前置

遇到了很多问题,这里做一个记录,部分步骤没有截图
I have encountered a lot of problems, here is a record, some steps have no screenshots

qemu

sudo apt-get install qemu
  • qemu-<两下tab> 
    

    会弹出qemu可以模拟的所有平台(All platforms that QEMU can be simulated will pop up)

busybox

官网:https://busybox.net/

进入busybox目录
Enter the busybox directory

make menuconfig

Q : HOSTCC scripts/basic/fixdep
/bin/sh: 1: gcc: not found
scripts/Makefile.host:90: recipe for target 'scripts/basic/fixdep' failed
make[1]: *** [scripts/basic/fixdep] Error 127
Makefile:532: recipe for target 'scripts_basic' failed
make: *** [scripts_basic] Error 2

A : 此报错是因为缺少gcc(This error is due to the lack of GCC)

sudo apt install gcc

Q : $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
HOSTCC scripts/kconfig/mconf.o
:0:12: fatal error: curses.h: 没有那个文件或目录
compilation terminated.
scripts/Makefile.host:108: recipe for target 'scripts/kconfig/mconf.o' failed
make[1]: *** [scripts/kconfig/mconf.o] Error 1
Makefile:541: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2

A : 这是因为ubuntu缺少ncurses devel套件,安装即可(This is because Ubuntu lacks NCURSES Devel kit, just install it)

sudo apt-get install libncurses5-dev

接着会进入settings
Then you will enter settings

  • 勾选Build static binary(no shared libs),因为动态链接需要额外的动态链接库,这样会使得系统文件变得很大(Check the `Build Static binary (no shared libs), because the dynamic link requires an additional dynamic link library, which will make the system file a large)
  • 安装目录(Destination path for "make install"(NEW))我设置的是./rootfs(Install the directory (Destination Path for" Make Install "(New) ./ROOTFS)
  • 保存退出(Save and exit)
make -j4
make install 

接着就会在busybox中看到生成的rootfs文件夹
Then you will see the generated rootfs folder

到这里做基本的内核pwn题基本的环境已经够了
It's enough to do the basic environment of the core PWN question here.

运行boot.sh:Could not access KVM Kernel module

qemu-system-x86_64 -initrd rootfs.cpio -kernel bzImage -append 'console=ttyS0 root=/dev/ram oops=panic panic=1' -enable-kvm -monitor /dev/null -m 64M --nographic  -smp cores=1,threads=1 -cpu kvm64,+smep

因为虚拟机缺少kvm,在run boot.sh的时候可以先将boot.sh的source_code里的-enable-kvm去掉,boot.sh就可以运行了
Because the virtual machine lacks KVM, when run boot.sh, you can first remove the source_code of boot.sh first.

重新打包系统文件(Re -pack the system file)

find . | cpio -o -H newc > ../rootfs.cpio

当然也可以写个pack.sh
Of course you can also write a Pack.sh

#!/bin/sh

cp -r rootfs rootfs_tmp
cp -r etc rootfs_tmp/
cp init rootfs_tmp/
cp babydriver.ko rootfs_tmp/

gcc -g -static exp.c -o exp
cp exp rootfs_tmp/

chmod +x rootfs_tmp/init
chmod g-w -R rootfs_tmp/
chmod o-w -R rootfs_tmp/
sudo chown -R root rootfs_tmp/
sudo chgrp -R root rootfs_tmp/
sudo chmod u+s rootfs_tmp/bin/busybox

cd rootfs_tmp
find . | cpio -o -H newc > ../rootfs.cpio
cd ..

sudo rm -rf rootfs_tmp

标签:tmp,Kernel,make,sudo,sh,environment,construction,scripts,rootfs
来源: https://www.cnblogs.com/M1sceden4/p/16217403.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有