今天无语中查了下阿里云虚拟主机的访问历史, 发现之前使用WordPress被莫名其妙的写入一堆英文的文章的原因查到了, 登录接口被暴力破解导致的, 所有时间比较急, 就写了个简单的POST请求的安全控制的代码, 使用也很简单, 直接在程序入口直接require 这个文件即可, 需要保证这个配置文件定义的限流锁文件保存路径具有写权限

可以看出, 一个登录请求了那么多次, 没办法, 紧急写了个比较粗糙的代码

<?php

// 简单的全局请求安全限制接口
class RequestLimit
{

    protected $configFilePath = 'request_limit.lock';
    protected $config = [
        'GET' => [],// 定义需要限流的类型, 如果不想写配置, 那么就默认以default配置为准
    ];
    protected $default = [
        'rate' => '10/60|20/600|30/3600|100/43200|200/86400', // 限制10次/60s, 20次/10分钟, 30次一小时
        'try_cont' => 0,
        'save_history_count' => 100, // 保留历史条数
        'try_history' => [],
    ];

    public function __construct()
    {
        if (file_exists($this->configFilePath)) {
            $this->config = json_decode(file_get_contents($this->configFilePath), true);
        }
    }

    public function handle($method)
    {
        if (!array_key_exists($method, $this->config)) {
            return;
        }
        if (empty($this->config[$method])) {
            $this->config[$method] = $this->default;
        }
        $this->config[$method]['try_history'] = empty($this->config[$method]['try_history']) ? [] : $this->config[$method]['try_history'];
        // 再次请求频率判断, 通过才让继续
        foreach (explode('|', $this->config[$method]['rate']) as $item) {
            [$x, $y] = explode('/', $item);
            if (!empty($this->config[$method]['try_history'][$x - 1]) && $this->config[$method]['try_history'][$x - 1] + $y >= time()) {
                header('HTTP/1.1 429 Too Many Requests');
                echo '429 Too Many Requests';
                exit;
            }
        }
        if (empty($this->config[$method]['save_history_count'])) {
            $this->config[$method]['save_history_count'] = 100;
        }
        array_unshift($this->config[$method]['try_history'], time());
        $this->config[$method]['try_history'] = array_slice($this->config[$method]['try_history'], 0, $this->config[$method]['save_history_count']);
        $this->config[$method]['try_cont'] = empty($this->config[$method]['try_cont']) ? 1 : $this->config[$method]['try_cont'] + 1;
        $this->saveConfig();
    }

    public function saveConfig()
    {
        file_put_contents($this->configFilePath, json_encode($this->config, 256));
    }
}

$q = new RequestLimit();
$q->handle($_SERVER['REQUEST_METHOD']);

Windows下的命令

# 删除所有路由(谨慎使用, 会导致127.0.0.1无法访问, 恢复后依然需要一段时间才能后遗症自动修复)
route -p delete *

# 修复链路(执行后需要重启)
netsh int ipv4 reset

// 链路设置(虽然设置成功了, 不知道怎么才有意义)
route -p add 192.168.0.117 mask 255.255.255.255 192.168.0.1 metric 5 if 2

查询当前链路情况
route print -4

跟踪访问的地址走的路径
tracert 192.168.5.11

先打开cmd

输入下面的命令回车

netsh wlan show profiles

显示如下

C:\Users\Administrator>netsh wlan show profiles

接口 WLAN 上的配置文件:


组策略配置文件(只读)
---------------------------------
    <无>

用户配置文件
-------------
    所有用户配置文件 : TP-LINK_CC04
    所有用户配置文件 : Tenda_931358
    所有用户配置文件 : Honor9
    所有用户配置文件 : changyi
    所有用户配置文件 : DIRECT-a8-Pantum M6200 Series
    所有用户配置文件 : TPGuest_F10D

比如我们需要查询第一个WiFi的密码

netsh wlan show profiles name="TP-LINK_CC04"  key=clear

显示如下

C:\Users\Administrator>netsh wlan show profiles name="TP-LINK_CC04"  key=clear

接口 WLAN 上的配置文件 TP-LINK_CC04:
=======================================================================

已应用: 所有用户配置文件

配置文件信息
-------------------
    版本                   : 1
    类型                   : 无线局域网
    名称                   : TP-LINK_CC04
    控制选项               :
        连接模式           : 自动连接
        网络广播           : 只在网络广播时连接
        AutoSwitch         : 请勿切换到其他网络
        MAC 随机化: 禁用

连接设置
---------------------
    SSID 数目              : 1
    SSID 名称              :“TP-LINK_CC04”
    网络类型               : 结构
    无线电类型             : [ 任何无线电类型 ]
    供应商扩展名           : 不存在

安全设置
-----------------
    身份验证         : WPA2 - 个人
    密码                 : CCMP
    身份验证         : WPA2 - 个人
    密码                 : GCMP
    安全密钥               : 存在
    关键内容            : 88888888

费用设置
-------------
    费用                : 无限制
    阻塞                : 否
    接近数据限制        : 否
    过量数据限制        : 否
    漫游                : 否
    费用来源            : 默认

执行composer install, composer update, php artisan tinker, php artisan cache:clear 等等等 . . .
都抛出下面的错误

  • 通过各种排查, 文件为下面这个路径的该文件
\vendor\laravel\framework\src\Illuminate\Container\Container.php
  • 最后问题还是解决了
在laravel的composer引入的公共文件中, 发现了使用request类的发放, 导致命令行无法正常的执行下去

<?php
function tree($directory)
{
    $mydir = dir($directory);
    echo "<ul>";
    while ($file = $mydir->read()) {
        if ($file == "." || $file == "..") {
            continue;
        }
        if (is_dir("$directory/$file")) {
            echo "<li><font color='blue'><b>$file/</b></font></li>";
            tree("$directory/$file");
        } else {
            echo "<li>$file</li>";
        }
    }
    echo "</ul>";
    $mydir->close();
}

echo "<h2>目录为蓝色</h2>";
tree(".");