当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

firewall

Firewall package for Laravel applications
授权协议 View license
开发语言 PHP
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 公良浩邈
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Firewall 2.2

Purpose

This a "soft-firewall" package. Its purpose is to help people prevent unauthorized access to routes by IP address. It is able to keep track of IPs, countries and hosts (dynamic ip), and redirect non-authorized users to, for instance, a "Coming Soon" page, while letting whitelisted IPs to have access to the entire site. It is now also able to detect and block attacks (too many requests) from single IPs or whole countries.

This package can prevent some headaches and help you block some access to your apps, but cannot replace firewalls and appliances, for attacks at the network level, you'll still need a real firewall.

Features

  • Control access to routes and groups via black and white lists.
  • Detect and block attacks to your application, from IP addresses or countries.
  • Send Slack notifications in attack events.
  • Allow whitelisted to access the whole site and send everyone else to a "coming soon page".
  • Redirect blacklisted users to some other page.
  • Use database or arrays to store IP lists.
  • Whitelist your development machine using a dynamic DNS host name.
  • Done using middleware, so you can protect/unprotect groups of routes.
  • All features are available for hosts, IP addresses, ranges of IP addresses and whole countries.
  • Super fast, less than 10ms increase in each request.
  • Highly configurable.

Concepts

Blacklist

All IP addresses in those lists will no be able to access routes filtered by the blacklist filter.

Whitelist

Those IP addresses, ranges or countries can

  • Access blacklisted routes even if they are in a range of blacklisted IP addresses.
  • Access 'allow whitelisted' filtered routes.
  • If a route is filtered by the 'allow whitelisted' filter and the IP is not whitelisted, the request will be redirected to an alternative url or route name.

Attack Detection

Firewall is able to detect simple attacks to your page, by counting requests from the same IP or country. Just enable it on your config/firewall.php and, to receive notifications, configure the Slack service in config/services.php:

'slack' => [
    'webhook_url' => env('SLACK_WEBHOOK_URL'),
],

and add the route notification method to your user model:

/**
 * Route notifications for the Slack channel.
 *
 * @return string
 */
public function routeNotificationForSlack()
{
    return config('services.slack.webhook_url');
}

IPs lists

IPs (white and black) lists can be stored in array, files and database. Initially database access to lists is disabled, so, to test your Firewall configuration you can publish the config file and edit the blacklist or whitelist arrays:

'blacklist' => array(
    '127.0.0.1',
    '192.168.17.0/24'
    '127.0.0.1/255.255.255.255'
    '10.0.0.1-10.0.0.255'
    '172.17.*.*'
    'country:br'
    '/usr/bin/firewall/blacklisted.txt',
),

The file (for instance /usr/bin/firewall/blacklisted.txt) must contain one IP, range or file name per line, and, yes, it will search for files recursively, so you can have a file of files if you need:

127.0.0.2
10.0.0.0-10.0.0.100
/tmp/blacklist.txt

Redirecting non-whitelisted IP addresses

Non-whitelisted IP addresses can be blocked or redirected. To configure redirection you'll have to publish the config.php file and configure:

'redirect_non_whitelisted_to' => 'coming/soon',

Artisan Commands

You have access to the following commands:

Global

  firewall:cache:clear  Clear the firewall cache.
  firewall:list         List all IP address, white and blacklisted.
  firewall:updategeoip  Update the GeoIP database.

When database is enabled

  firewall:blacklist          Add an IP address to blacklist.
  firewall:clear              Remove all ip addresses from white and black lists.
  firewall:remove             Remove an IP address from white or black list.
  firewall:whitelist          Add an IP address to whitelist.

Those are results from firewall:list:

+--------------+-----------+-----------+
| IP Address   | Whitelist | Blacklist |
+--------------+-----------+-----------+
| 10.17.12.7   |           |     X     |
| 10.17.12.100 |     X     |           |
| 10.17.12.101 |     X     |           |
| 10.17.12.102 |     X     |           |
| 10.17.12.200 |           |     X     |
+--------------+-----------+-----------+
+-----------------------+-----------+-----------+
| IP Address            | Whitelist | Blacklist |
+-----------------------+-----------+-----------+
| 172.0.0.0-172.0.0.255 |           |     X     |
| country:br            |           |     X     |
| host:mypc.myname.com  |     X     |           |
+-----------------------+-----------+-----------+

Facade

You can also use the Firewall Facade to manage the lists:

$whitelisted = Firewall::isWhitelisted('10.17.12.1');
$blacklisted = Firewall::isBlacklisted('10.0.0.3');

Firewall::whitelist('192.168.1.1');
Firewall::blacklist('10.17.12.1', true); /// true = force in case IP is whitelisted
Firewall::blacklist('127.0.0.0-127.0.0.255');
Firewall::blacklist('200.212.331.0/28');
Firewall::blacklist('country:br');

if (Firewall::whichList($ip) !== false)  // returns false, 'whitelist' or 'blacklist'
{
    Firewall::remove($ip);
}

Return a blocking access response:

return Firewall::blockAccess();

Suspicious events will be (if you wish) logged, so tail it:

php artisan tail

Blocking Whole Countries

You can block a country by, instead of an ip address, pass country:<2-letter ISO code>. So, to block all Brazil's IP addresses, you do:

php artisan firewall:blacklist country:br

You will have to add this requirement to your composer.json file:

"geoip/geoip": "~1.14"

or

"geoip2/geoip2": "~2.0"

You need to enable country search on your firewall.php config file:

'enable_country_search' => true,

And you can schedule this command to update your cities GeoIp database regularly:

php artisan firewall:updategeoip

You can find those codes here: isocodes

Session Blocking

You can block users from accessing some pages only for the current session, by using those methods:

Firewall::whitelistOnSession($ip);
Firewall::blacklistOnSession($ip);
Firewall::removeFromSession($ip);

Playground & Bootstrap App

Click here to see it working and in case you need a help figuring out things, try this repository.

Installation

Compatible with

  • Laravel 4+ (version 1.*)
  • Laravel 5.0, 5.1, 5.2 and 5.3 (version 1.*)
  • Laravel 5.4, 5.5, 5.6 and 5.7 (version 2.*)

Installing

Require the Firewall package using Composer:

composer require pragmarx/firewall
  • Laravel 5.5 and up

    You don't have to do anything else, this package uses Package Auto-Discovery's feature, and should be available as soon as you install it via Composer.

  • Laravel 5.4 and below

    Add the Service Provider and the Facade to your app/config/app.php:

PragmaRX\Firewall\Vendor\Laravel\ServiceProvider::class,
'Firewall' => PragmaRX\Firewall\Vendor\Laravel\Facade::class,

Add middlewares to your app/Http/Kernel.php

protected $routeMiddleware = [
    ...
    'fw-only-whitelisted' => \PragmaRX\Firewall\Middleware\FirewallWhitelist::class,
    'fw-block-blacklisted' => \PragmaRX\Firewall\Middleware\FirewallBlacklist::class,
    'fw-block-attacks' => \PragmaRX\Firewall\Middleware\BlockAttacks::class,
];

or

protected $middlewareGroups = [
    'web' => [
        ...
    ],

    'api' => [
        ...
    ],
    
    'firewall' => [
        \PragmaRX\Firewall\Middleware\FirewallBlacklist::class,
        \PragmaRX\Firewall\Middleware\BlockAttacks::class,
    ],
];

Then you can use them in your routes:

Route::group(['middleware' => 'fw-block-blacklisted'], function () 
{
    Route::get('/', 'HomeController@index');
});

Or you could use both. In the following example the allow group will give free access to the 'coming soon' page and block or just redirect non-whitelisted IP addresses to another, while still blocking access to the blacklisted ones.

Route::group(['middleware' => 'fw-block-blacklisted'], function () 
{
    Route::get('coming/soon', function()
    {
        return "We are about to launch, please come back in a few days.";
    });

    Route::group(['middleware' => 'fw-only-whitelisted'], function () 
    {
        Route::get('/', 'HomeController@index');
    });
});

Note: You can add other middleware you have already created to the new groups by simplyadding it to the fw-allow-wl or fw-block-bl middleware group.

Migrate your database

php artisan migrate

Warning: If you already have a Firewall package installed and migrated, you need to update your migration name, in the migrations table, to 2014_02_01_311070_create_firewall_table, otherwise the migrate command will fail tell you the table already exists.

To publish the configuration file you'll have to:

Laravel 4

php artisan config:publish pragmarx/firewall

Laravel 5

php artisan vendor:publish --provider="PragmaRX\Firewall\Vendor\Laravel\ServiceProvider"

TODO

  • Tests, tests, tests.

Author

Antonio Carlos Ribeiro

License

Firewall is licensed under the BSD 3-Clause License - see the LICENSE file for details

Contributing

Pull requests and issues are more than welcome.

  • firewall 防火墙 参数 –permanent 永久生效 –add-port= 允许访问的某个端口号(包括协议名) –remove-port= 移除允许访问的端口号 –zone= 设置区域 (区域可选,也可以不打这个参数 –list-all 显示所有指定区域的所有规则(不是永久生效不显示 –reload 重新加载 (打完所有命令后记得打这个 放行8099端口 [root@wk ~]# fir

  • 1、firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status firewalld 开机禁用 : systemctl disable firewalld 开机启用 : systemctl enable firewalld 2.systemctl是CentOS7的服务

  • 1.开启firewall服务 systemctl start firewalld 2.关闭firewall服务 systemctl stop firewalld 3.移除firewall服务 systemctl disable firewalld 4.查看firewall状态 systemctl status firewalld 5.显示网络接口ens160的对应区域 firewall-cmd -

  • /etc/config/dropbear Sections The dropbear configuration contains settings for the dropbear SSH server in a single section. Dropbear The dropbear section contains these settings: Name Type Required De

  • [--permanent] [--zone=zone] --list-protocols            List protocols added for zone as a space separated list. If zone is            omitted, default zone will be used.        [--permanent] [--zone=

  • systemctl restart firewalld //重启防火墙 firewall-cmd --reload //重新加载防火墙配置 systemctl start firewalld.service //开启服务 systemctl enable firewalld.service //开机制动启动 systemctl stop firewalld.service //关闭

  • win7 开启防火墙:net start MpsSvr (一) 需要额外的:ipmontr.dll 阻止端口: 出站规则设置: netsh advfirewall firewall add rule name="hold8880" protocol=TCP dir=out localport=8880 action=block 入站规则设置: netsh advfirewall firewal

  • iptables iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT -A表示添加,INPUT表示添加的位置 -D表示删除 -s表示源,192.168.1.0/24表示数据包中源ip是192.168.1.0/24网段将会被匹配 -p表示协议,tcp就表示匹配的协议是tcp将会被匹配 --dport表示目的端口 22就表示

  • 卸载Firewall并安装iptables后重新安装回Firewall。安装Firewall启动时,提示Failed to start firewalld.service: Unit firewalld.service is masked. 搜索尝试了大神们的解决方法,输入指令 systemctl unmask firewalld.service 此时可以正常启动Firewall了。 接下来顺便讲

  • 版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp The essential guide to understanding and using firewalls to protect personal computers and your network *An

  • 需求:只允许三台服务器访问缓存服务器 首先检查: firewall-cmd --get-default-zone 根据输出是否是public执行:firewall-cmd --set-default-zone=public; firewall-cmd --get-active-zones       根据输出是否是public interfaces:eth0执行:firewall-cmd --zo

  • 一、firewall配置 The configuration for firewalld is stored in various XML files in /usr/lib/firewalld/ and /etc/firewalld/. This allows a great deal of flexibility as the files can be edited, written to,

  • firewall端口策略以及转发 firewall-cmd --add-service=mysql # 开放mysql端口 firewall-cmd --remove-service=http # 阻止http端口 firewall-cmd --list-services # 查看开放的服务 firewall-cmd --add-port=3306/tcp # 开放通过tcp访问3306 fire

  • 安装Firewall命令: yum install firewalld firewalld-config Firewall开启常见端口命令: firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=53/udp --permanent Firewall关闭常见端口命

  • 1. 执行命令Rundll32 setupapi,InstallHinfSection Ndi-Steelhead 132 %windir%\inf\netrass.inf 2. Restart Windows 3. 执行命令Netsh firewall reset   如果以上步骤还是不能重置firewall on/off,可以先 1. 关闭ICS service (net stop share

  • root@OpenWrt:/etc/config# ls 4g dataUsageCfg network 8192eeshare dhcp qos 8192eewpa dropbear remoteupgrade APNProf

  • FIREWALL-CMD(1) firewall-cmd FIREWALL-CMD(1) NAME firewall-cmd - firewalld command line client SYNOPSIS firewall-cmd [OPTIONS...] DESCRIPTION firewall-cmd is the command line client of the firewall

相关阅读

相关文章

相关问答

相关文档