【BugkuCTF】Whois

直接访问http://49.232.142.230:15900/query.php

会直接爆出源码

复制代码
<?php

error_reporting(0);

$output = null;
$host_regex = "/^[0-9a-zA-Z][0-9a-zA-Z\.-]+$/";
$query_regex = "/^[0-9a-zA-Z\. ]+$/";


if (isset($_GET['query']) && isset($_GET['host']) && 
      is_string($_GET['query']) && is_string($_GET['host'])) {

  $query = $_GET['query'];
  $host = $_GET['host'];
  
  if ( !preg_match($host_regex, $host) || !preg_match($query_regex, $query) ) {
    $output = "Invalid query or whois host";
  } else {
    $output = shell_exec("/usr/bin/whois -h ${host} ${query}");
  }

} 
else {
  highlight_file(__FILE__);
  exit;
}

?>

<!DOCTYPE html>
<html>
  <head>
    <title>Whois</title>
  </head>
  <body>
    <pre><?= htmlspecialchars($output) ?></pre>
  </body>
</html>

具体执行的命令大概如下所示

复制代码
/usr/bin/whois -h whois.verisign-grs.com baidu.com

但是这里需要绕正则,通过正则可知我们无法使用常规的方法来拼接命令

复制代码
# host参数只能由0-9、a-z、A-Z、.(点)、-(减号)以及\n或者\r 组成
$host_regex = "/^[0-9a-zA-Z][0-9a-zA-Z\.-]+$/";
# query参数只能由0-9、a-z、A-Z、.(点)、 (空格)以及\n或者\r组成
$query_regex = "/^[0-9a-zA-Z\. ]+$/";

可以看到**\n换行符** 和**\r回车符**是可以用的

这里回车符不行,但是换行符可以

这样子后端的命令就变成了

复制代码
/usr/bin/whois -h whois.verisign-grs.com
ls
相关推荐
一名优秀的码农1 天前
vulhub系列-57-Thoth Tech: 1(超详细)
安全·web安全·网络安全·网络攻击模型·安全威胁分析
汤愈韬1 天前
路由反射器实验、环回接口建立IBGP邻居、更新源检查机制
网络·网络协议·网络安全·security
童话的守望者1 天前
应急响应靶机练习-Web2
网络安全
huangwxiao2 天前
HTB——Oopsie
linux·网络安全·htb
Echo-J2 天前
WinDbg 双机调试(调试机为Windows11系统,被调试机为Windows7系统)
安全·网络安全·云计算·系统安全
67X2 天前
【论文写作】基于深度学习的异常检测方法(Deep learning-based anomaly detection methods)
深度学习·网络安全
菩提小狗2 天前
每日安全情报报告 · 2026-04-05
网络安全·漏洞·cve·安全情报·每日安全
oi..2 天前
Python POST请求练习-ua
开发语言·网络·经验分享·python·安全·web安全·网络安全
vortex52 天前
一文厘清DDoS与CC攻击
网络·网络安全·渗透测试·ddos
淼淼爱喝水2 天前
解决 DVWA 联合注入报错:Illegal mix of collations for operation ‘UNION‘ 全指南
网络安全