草庐IT

BugKu_never_give_up

嘉沐のBlog 2023-03-28 原文
if(!$_GET['id'])
{
	header('Location: hello.php?id=1');
	exit();
}
$id=$_GET['id'];
$a=$_GET['a'];
$b=$_GET['b'];
if(stripos($a,'.'))
{
	echo 'no no no no no no no';
	return ;
}
$data = @file_get_contents($a,'r');
if($data=="bugku is a nice plateform!" and $id==0 and strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4)
{
	$flag = "flag{***********}";
}
else
{
	print "never never never give up !!!";
}


?>

2023年2月23日遇到的一个php代码审计的题目,这个题目的考察知识点非常多,写个wp记录一下。

if(!$_GET['id'])
{
	header('Location: hello.php?id=1');
	exit();
}

如果id=0或者没有设置id的值,则跳转id=1,程序退出

$id=$_GET['id'];
$a=$_GET['a'];
$b=$_GET['b'];
if(stripos($a,'.'))
{
	echo 'no no no no no no no';
	return ;
}

三个参数 id a b ,其中a参数的值不能有'.',如果有,则输出'no no no',并返回。

$data = @file_get_contents($a,'r');

file_get_contents从$a里读取数据,然后将数据给变量$data存储。

if($data=="bugku is a nice plateform!" and $id==0 and strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4)
{
	$flag = "flag{***********}";
}
else
{
	print "never never never give up !!!";
}

这个判断非常有意思,有很多矛盾的地方。首先data的值必须是"bugku is a nice plateform!",id必须为0(第一段代码就表示过id!=0),b的长度必须大于5,在正则匹配时,“111”和b的第一个字符拼接必须匹配到”1114“,但是b的第一个字符又不能是4。整个过程都非常矛盾,但是这正是考察php的知识点。

首先,data的值必须是"bugku is a nice plateform!",这个怎么办到?我们知道file_get_contents的参数是文件名,本质上是打开一个文件流,从流里读出文件内容。但我们并不知道哪个文件里有这个字符串信息,也没有上传接口,无法自己上传一个文件上去。这时,需要观察到本质,file_get_contents本质上是打开一个文件流,流!!!,重点是流。我们可以用php伪协议来完成。

php://input  // 读取post输入流

此时$a=php://input,然后用post传输"bugku is a nice plateform!",当file_get_contents($a)触发时,就是从Post的输入流里获取字符串“bugku is a nice plateform!”。

接着,id==0怎么绕过,毕竟一开始就判断过,id肯定不能是0,要是0,就退出程序了。但仔细看看,==在php中是弱类型比较,0bcde==0这个是成立的。为什么呢?因为数字之间比较时,非数字不参与比较。因此id=0a就可以绕过。

strlen($b) >5 没什么可说的,个数大于5就好。

eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4),按照普遍的思路来说

eregi("111".substr($b,0,1),"1114")   

eregi()匹配函数,匹配到则是True

"111".substr($b,0,1)  ->  拼接 “111”和  $b的第一个字符  (.是拼接字符串的意思)

比如$b=4321    那么  "111".substr($b,0,1) 就是1114

但是,绕过就是不走寻常路。令b=*12345。*号是通配符,匹配所有。因此,直接绕过!!!

整体构造如下:

有关BugKu_never_give_up的更多相关文章

  1. ruby - Rails 路由 : Giving default values for path helpers - 2

    有什么方法可以为url/path助手提供默认值吗?我有一个可选范围环绕我的所有路线:#config/routes.rbFoo::Application.routes.drawdoscope"(:current_brand)",:constraints=>{:current_brand=>/(foo)|(bar)/}do#...allotherroutesgohereendend我希望用户能够使用这些URL访问网站:/foo/some-place/bar/some-place/some-place为了方便起见,我在我的ApplicationController中设置了一个@current

  2. ruby-on-rails - 冒号(:) gives load error in locale YAML file - 2

    我在en:语言环境中有一个字符串display_device:toplay:getplayer冒号给我的错误是cannotloadtranslationsfromC:/DocumentsandSettings/rajg/discoveryaws/branches/internationalization/config/locales/en.yml,expectedittoreturnahash,butdoesnot我怎样才能让它工作? 最佳答案 如果你用这样的引号将它括起来,你可以在你的字符串中转义冒号(和其他“重要”字符):dis

  3. ruby - Rubocop 规则 : Never use 'do' with multi-line 'while - 2

    我有以下代码#coloursarandomcellwithacorrectcolourdefcolour_random!whiletruedocol,row=rand(columns),rand(rows)cell=self[row,col]ifcell.empty?thencell.should_be_filled??cell.colour!(1):cell.colour!(0)breakendendend做什么并不重要,尽管它应该很明显。关键是Rubocop给了我一个警告Neveruse'do'withmulti-line'while为什么我不应该那样做?那我该怎么办呢?

  4. ruby-on-rails - 每当 gem : I set :output but the logfile doesn't show up where I'd expect it to - 2

    在我的schedule.rb文件中,我有以下几行:set:output,'/log/cron_log.log'every5.minutesdocommand'echo"hello"'end我按照这个问题Rails,usingwhenevergemindevelopment中的建议运行了whenever-w,并且我假设cronfile已编写并正在运行。(我也尝试重新启动Rails服务器。)当我运行$crontab-l时,我看到以下内容:0,5,10,15,20,25,30,35,40,45,50,55****/bin/bash-l-c'echo"hello">>/log/cron_log

  5. ruby-on-rails - Rails 设计 : "You need to sign in or sign up before continuing" instead of "You will receive an email with instructions.." - 2

    我已经安装了DeviseonRails4.2.0,一切似乎都在工作,我使用了以下指南:http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/我的设计模块是:devise:database_authenticatable,:registerable,:confirmable,:recoverable,:rememberable,:trackable,:validatable,:omniauthable唯一的问题是,如果我尝试通过转到注册页面创建一个新帐户,然后在输入我的电子邮

  6. ruby-on-rails - Rails add_index 算法 : :concurrently still causes database lock up during migration - 2

    为了防止在迁移到生产站点期间出现数据库事务错误,我们遵循了https://github.com/LendingHome/zero_downtime_migrations中列出的建议。(具体由https://robots.thoughtbot.com/how-to-create-postgres-indexes-concurrently-in概述),但在特别大的表上创建索引期间,即使是索引创建的“并发”方法也会锁定表并导致该表上的任何ActiveRecord创建或更新导致各自的事务失败有PG::InFailedSqlTransaction异常。下面是我们运行Rails4.2(使用Acti

  7. ruby-on-rails - Jobs with Resque gives "Don' t know how to build task 'jobs:work' "on Heroku - 2

    我遵循了https://devcenter.heroku.com/articles/queuing-ruby-resque上的教程在Rails应用程序中排队和运行后台作业。在对作业进行排队后,它似乎没有运行任何作业,因为在控制台中我可以看到作业尚未处理>Resque.info=>{:pending=>1,:processed=>0,:queues=>1,:workers=>0,:working=>0,:failed=>0,:servers=>["redis://dory.redistogo.com:9826/0"],:environment=>"production"}如果我尝试(本地

  8. ruby - 如何将 Ruby 哈希 "up"中的属性移动一级 - 2

    x={:name=>"John",:data=>{:physical=>{:age=>25,:weight=>150}}}我希望将数据的子属性向上移动一个级别(但不一定只是简单地展平所有属性)。在这种情况下,我基本上想将:physical属性“向上”移动一个级别。我正在尝试这个y=x[:data']y.each{|key|x[key]=y[key]}但是我得到...x=x.except(:data)=>{:name=>"John",[:physical,{:age=>25,:weight=>150}]=>nil}我在找...=>{:name=>"John",:physical=>{:a

  9. ruby-on-rails - Rails4 : Why resque worker is not picking up jobs - 2

    我在我的Rails4应用程序中使用resque和resque_scheduler。我的应用程序正在为resque提供一些工作,但工作人员没有在处理这些工作。reque-web显示没有失败。我已经通过运行开始resqueworkerQUEUE=kqueuerakeenvironmentresque:work我的rails控制台2.0.0p353:006>Resque.info=>{:pending=>0,:processed=>0,:queues=>0,:workers=>1,:working=>0,:failed=>0,:servers=>["redis://localhost:637

  10. ruby - DRY up Ruby 三元 - 2

    我经常有这样一种情况,我想做一些条件逻辑,然后返回一部分条件。如何在不重复true或false表达式中的条件部分的情况下执行此操作?例如:ClassName.method.blank??false:ClassName.method有没有办法避免重复ClassName.method?这是一个真实世界的例子:PROFESSIONAL_ROLES.key(self.professional_role).nil??948460516:PROFESSIONAL_ROLES.key(self.professional_role) 最佳答案 假设

随机推荐