0
点赞
收藏
分享

微信扫一扫

公众号开发DAY1:natapp内网穿透接入公众号(php)

sin信仰 2022-03-23 阅读 58

新浪云我token一直失败,放弃了选择natapp内网渗透

natapp申请隧道

  1. natapp官网 ,点击natapp官网地址https://natapp.cn/,注册账号并实名认证,客户端下载,购买隧道;在这里插入图片描述

  2. 点击natapp客户端 点击natapp.exe,输入 natapp -authtoken 隧道anthtoken在这里插入图片描述

本地项目搭建

  1. 安装下载wamp wamp集成php+mysql+apache,在www目录下加入项目文件;在这里插入图片描述wamp启动服务在这里插入图片描述

  2. 公众号URL接入验证 在项目中写入wxapi.php下面展示一些 wxapi.php,其中define(“TOKEN”, “weixin”),weixin要与微信公众平台中的token一致。

<?php
/**
  * wechat php test
  */

//define your token
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if($_GET["echostr"]){
    $wechatObj->valid();
}else{
    $wechatObj->responseMsg();
}


class wechatCallbackapiTest
{
	public function valid()
    {
        $echoStr = $_GET["echostr"];

        //valid signature , option
        if($this->checkSignature()){
        	echo $echoStr;
        	exit;
        }
    }

    public function responseMsg()
    {
		//get post data, May be due to the different environments
		$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

      	//extract post data
		if (!empty($postStr)){
                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
                   the best way is to check the validity of xml by yourself */
                libxml_disable_entity_loader(true);
              	$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername = $postObj->FromUserName;
                $toUsername = $postObj->ToUserName;
                $keyword = trim($postObj->Content);
                $time = time();
                $textTpl = "<xml>
							<ToUserName><![CDATA[%s]]></ToUserName>
							<FromUserName><![CDATA[%s]]></FromUserName>
							<CreateTime>%s</CreateTime>
							<MsgType><![CDATA[%s]]></MsgType>
							<Content><![CDATA[%s]]></Content>
							<FuncFlag>0</FuncFlag>
							</xml>";             
				if(!empty( $keyword ))
                {
              		$msgType = "text";
                	$contentStr = "Welcome to wechat world!";
                	$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                	echo $resultStr;
                }else{
                	echo "Input something...";
                }

        }else {
        	echo "";
        	exit;
        }
    }
		
	private function checkSignature()
	{
        // you must define TOKEN by yourself
        if (!defined("TOKEN")) {
            throw new Exception('TOKEN is not defined!');
        }
        
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
        		
		$token = TOKEN;
		$tmpArr = array($token, $timestamp, $nonce);
        // use SORT_STRING rule
		sort($tmpArr, SORT_STRING);
		$tmpStr = implode( $tmpArr );
		$tmpStr = sha1( $tmpStr );
		
		if( $tmpStr == $signature ){
			return true;
		}else{
			return false;
		}
	}
}

?>

访问wxapi.php如下,则成功
在这里插入图片描述

  1. 微信公众平台填写基本配置 URL如下在这里插入图片描述

在这里插入图片描述配置成功在这里插入图片描述

举报

相关推荐

0 条评论