Compare commits
4 commits
master
...
debian-sid
Author | SHA1 | Date | |
---|---|---|---|
Benoît S. | b3b58a90cd | ||
Benoît S. | fd49d009b6 | ||
Benoît S. | b57bf34430 | ||
Benoît S. | 30a3d605e1 |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
*.swp
|
|
||||||
.vagrant
|
|
76
CHANGELOG.md
76
CHANGELOG.md
|
@ -1,76 +0,0 @@
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
||||||
and this project **does not adhere to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)**.
|
|
||||||
|
|
||||||
## [Unreleased]
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
* safe-start and safe-restart
|
|
||||||
* Chain MINIFW-DOCKER-INPUT-MANUAL for more granular/manual filtering of incoming traffic to services inside docker
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
### Deprecated
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
* fix interactive mode detection
|
|
||||||
|
|
||||||
### Security
|
|
||||||
|
|
||||||
## [23.07] - 2023-07-04
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
* new "check-active-config" command to check if the active configuration is th e same as the one persisted to disk
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* capture cmp(1) error output
|
|
||||||
* early error if script is not run as root
|
|
||||||
* extract "include_files" function
|
|
||||||
* print help/usage with list of possible commands
|
|
||||||
|
|
||||||
## [23.02] - 2023-02-01
|
|
||||||
|
|
||||||
* Export status without colors (to keep clean diffs)
|
|
||||||
|
|
||||||
## [22.06] - 2022-06-06
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* Configure sysctl values to IPv6 when applicable
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
* status output (number of # in headers)
|
|
||||||
|
|
||||||
## [22.05] - 2022-05-10
|
|
||||||
|
|
||||||
#### Fixed
|
|
||||||
|
|
||||||
* status output (number of # in headers)
|
|
||||||
|
|
||||||
## [22.04] - 2022-04-28
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
* markers for each section of status output
|
|
||||||
* store and compare state between restart
|
|
||||||
* colorize output if terminal supports colors
|
|
||||||
* simple syslog logging
|
|
||||||
* "version" action
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* use long options in some places
|
|
||||||
* output is normalized
|
|
||||||
* source legacy config after macros but before DROP policy
|
|
||||||
* source configuration only for valid actions
|
|
||||||
* improve legacy config parsing
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
* force remove temporary files
|
|
674
LICENSE
674
LICENSE
|
@ -1,674 +0,0 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
4
PACKAGING.md
Normal file
4
PACKAGING.md
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$ git checkout debian-sid
|
||||||
|
$ debmake -t
|
||||||
|
... edit rules, changelog, ...
|
||||||
|
$ dpkg-buildpackage
|
54
README.md
54
README.md
|
@ -1,49 +1,11 @@
|
||||||
Minifirewall
|
minifirewall is shellscripts for easy firewalling on a standalone server
|
||||||
=========
|
|
||||||
|
|
||||||
Minifirewall is shellscripts for easy firewalling on a standalone server
|
|
||||||
we used netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
|
we used netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
|
||||||
See https://gitea.evolix.org/evolix/minifirewall
|
See https://forge.evolix.org/projects/minifirewall
|
||||||
|
|
||||||
## Install
|
Usage :
|
||||||
|
-------
|
||||||
|
|
||||||
~~~
|
* download minifirewall and minifirewall.conf
|
||||||
install --mode 0700 minifirewall /etc/init.d/minifirewall
|
* copy minifirewall.conf in /etc (for Debian, use /etc/default/minifirewall)
|
||||||
install --mode 0600 minifirewall.conf /etc/default/minifirewall
|
and configure it
|
||||||
mkdir --mode 0700 /etc/minifirewall.d
|
* start / stop with : minifirewall start / minifirewall stop
|
||||||
~~~
|
|
||||||
|
|
||||||
## Config
|
|
||||||
|
|
||||||
Edit /etc/default/minifirewall file:
|
|
||||||
|
|
||||||
* If your interface is not `eth0`, change `INT` variable
|
|
||||||
* If you don't use IPv6, set `IPv6='off'`
|
|
||||||
* Modify `INTLAN` variable, probably with your `<IP>/32` or your local network if you trust it
|
|
||||||
* Set your trusted and privilegied IP addresses in `TRUSTEDIPS` and `PRIVILEGIEDIPS` variables
|
|
||||||
* Authorize your **public** services with `SERVICESTCP1` and `SERVICESUDP1` variables
|
|
||||||
* Authorize your **semi-public** services (only for `TRUSTEDIPS` and `PRIVILEGIEDIPS` ) with `SERVICESTCP2` and `SERVICESUDP2` variables
|
|
||||||
* Authorize your **private** services (only for `TRUSTEDIPS` ) with `SERVICESTCP3` and `SERVICESUDP3` variables
|
|
||||||
* Configure your authorizations for external services : DNS, HTTP, HTTPS, SMTP, SSH, NTP
|
|
||||||
* Add your specific rules
|
|
||||||
|
|
||||||
### Docker
|
|
||||||
|
|
||||||
To use minifirewall with Docker you need to change the variable `DOCKER='on'`
|
|
||||||
Then, authorisation for public/semi-public/private ports will also work for dockerized services
|
|
||||||
|
|
||||||
**WARNING** : When the port mapping on the host is different than in the container (ie: listen on :8090 on the host, but the service in the container listen on :8080)
|
|
||||||
you need to use the port used by the container (ie: 8080) in the public/semi-public/private port list
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
~~~
|
|
||||||
/etc/init.d/minifirewall start/stop/restart
|
|
||||||
~~~
|
|
||||||
|
|
||||||
If you want to add minifirewall in boot sequence, add the start command to `/usr/share/scripts/alert5`.
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
This is an [Evolix](https://evolix.com) project and is licensed
|
|
||||||
under the GPLv3, see the [LICENSE](LICENSE) file for details.
|
|
||||||
|
|
34
Vagrantfile
vendored
34
Vagrantfile
vendored
|
@ -1,34 +0,0 @@
|
||||||
# -*- mode: ruby -*-
|
|
||||||
# vi: set ft=ruby :
|
|
||||||
|
|
||||||
# Load ~/.VagrantFile if exist, permit local config provider
|
|
||||||
vagrantfile = File.join("#{Dir.home}", '.VagrantFile')
|
|
||||||
load File.expand_path(vagrantfile) if File.exists?(vagrantfile)
|
|
||||||
|
|
||||||
Vagrant.configure('2') do |config|
|
|
||||||
config.vm.synced_folder "./", "/vagrant", type: "rsync", rsync__exclude: [ '.vagrant', '.git' ]
|
|
||||||
config.ssh.shell="/bin/sh"
|
|
||||||
|
|
||||||
deps = <<SCRIPT
|
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables
|
|
||||||
SCRIPT
|
|
||||||
|
|
||||||
install = <<SCRIPT
|
|
||||||
ln -fs /vagrant/minifirewall /etc/init.d/minifirewall
|
|
||||||
ln -fs /vagrant/minifirewall.conf /etc/default/minifirewall
|
|
||||||
mkdir -p /etc/minifirewall.d
|
|
||||||
SCRIPT
|
|
||||||
|
|
||||||
post = <<SCRIPT
|
|
||||||
sed -i "s|^TRUSTEDIPS='|TRUSTEDIPS='192.168.121.0/24 |" /etc/default/minifirewall
|
|
||||||
SCRIPT
|
|
||||||
|
|
||||||
config.vm.define "minifirewall" do |node|
|
|
||||||
node.vm.hostname = "minifirewall"
|
|
||||||
node.vm.box = "debian/bookworm64"
|
|
||||||
config.vm.provision "deps", type: "shell", inline: deps
|
|
||||||
config.vm.provision "install", type: "shell", inline: install
|
|
||||||
config.vm.provision "post", type: "shell", inline: post
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
8
debian/README.Debian
vendored
Normal file
8
debian/README.Debian
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
minifirewall for Debian
|
||||||
|
|
||||||
|
Please edit this to provide information specific to
|
||||||
|
this minifirewall Debian package.
|
||||||
|
|
||||||
|
(Automatically generated by debmake Version 4.2.9)
|
||||||
|
|
||||||
|
-- Benoît SÉRIE <bserie@evolix.fr> Sat, 05 Aug 2017 21:29:51 +0200
|
5
debian/changelog
vendored
Normal file
5
debian/changelog
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
minifirewall (0~1708051929-1) UNRELEASED; urgency=low
|
||||||
|
|
||||||
|
* Initial release.
|
||||||
|
|
||||||
|
-- Benoît SÉRIE <bserie@evolix.fr> Sat, 05 Aug 2017 21:29:51 +0200
|
1
debian/compat
vendored
Normal file
1
debian/compat
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
9
|
15
debian/control
vendored
Normal file
15
debian/control
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Source: minifirewall
|
||||||
|
Section: unknown
|
||||||
|
Priority: extra
|
||||||
|
Maintainer: Benoît SÉRIE <bserie@evolix.fr>
|
||||||
|
Build-Depends: debhelper (>=9)
|
||||||
|
Standards-Version: 3.9.8
|
||||||
|
Homepage: https://forge.evolix.org/projects/minifirewall
|
||||||
|
|
||||||
|
Package: minifirewall
|
||||||
|
Architecture: any
|
||||||
|
Multi-Arch: foreign
|
||||||
|
Depends: ${misc:Depends}, ${shlibs:Depends}
|
||||||
|
Description: minimalist firewall
|
||||||
|
This Debian binary package was auto-generated by the
|
||||||
|
debmake(1) command provided by the debmake package.
|
45
debian/copyright
vendored
Normal file
45
debian/copyright
vendored
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||||
|
Upstream-Name: minifirewall
|
||||||
|
Source: <url://example.com>
|
||||||
|
#
|
||||||
|
# Please double check copyright with the licensecheck(1) command.
|
||||||
|
|
||||||
|
Files: README.md
|
||||||
|
blacklist-countries.sh
|
||||||
|
cron_minifirewall
|
||||||
|
minifirewall.conf
|
||||||
|
ripe.sh
|
||||||
|
Copyright: __NO_COPYRIGHT_NOR_LICENSE__
|
||||||
|
License: __NO_COPYRIGHT_NOR_LICENSE__
|
||||||
|
|
||||||
|
Files: minifirewall
|
||||||
|
Copyright: 2007-2015 Evolix
|
||||||
|
License: GPL-2.0
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License.
|
||||||
|
.
|
||||||
|
Description
|
||||||
|
script for standalone server
|
||||||
|
.
|
||||||
|
Start or stop minifirewall
|
||||||
|
.
|
||||||
|
BEGIN INIT INFO
|
||||||
|
Provides: minfirewall
|
||||||
|
Required-Start:
|
||||||
|
Required-Stop:
|
||||||
|
Should-Start: $network $syslog $named
|
||||||
|
Should-Stop: $syslog
|
||||||
|
Default-Start: 2 3 4 5
|
||||||
|
Default-Stop: 0 1 6
|
||||||
|
Short-Description: start and stop the firewall
|
||||||
|
Description: Firewall designed for standalone server
|
||||||
|
END INIT INFO
|
||||||
|
.
|
||||||
|
On Debian systems, the complete text of the GNU General Public License
|
||||||
|
Version 2 can be found in `/usr/share/common-licenses/GPL-2'.
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following
|
||||||
|
# license/copyright files.
|
1
debian/minifirewall.default
vendored
Normal file
1
debian/minifirewall.default
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
minifirewall.conf
|
1
debian/minifirewall.install
vendored
Normal file
1
debian/minifirewall.install
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
minifirewall usr/bin
|
32
debian/patches/add_packaging_informations
vendored
Normal file
32
debian/patches/add_packaging_informations
vendored
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
Description: Added a MD file for packaging informations
|
||||||
|
TODO: Put a short summary on the line above and replace this paragraph
|
||||||
|
with a longer explanation of this change. Complete the meta-information
|
||||||
|
with other relevant fields (see below for details). To make it easier, the
|
||||||
|
information below has been extracted from the changelog. Adjust it or drop
|
||||||
|
it.
|
||||||
|
.
|
||||||
|
minifirewall (0~1708051929-1) UNRELEASED; urgency=low
|
||||||
|
.
|
||||||
|
* Initial release.
|
||||||
|
Author: Benoît SÉRIE <bserie@evolix.fr>
|
||||||
|
|
||||||
|
---
|
||||||
|
The information above should follow the Patch Tagging Guidelines, please
|
||||||
|
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
|
||||||
|
are templates for supplementary fields that you might want to add:
|
||||||
|
|
||||||
|
Origin: <vendor|upstream|other>, <url of original patch>
|
||||||
|
Bug: <url in upstream bugtracker>
|
||||||
|
Bug-Debian: https://bugs.debian.org/<bugnumber>
|
||||||
|
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
|
||||||
|
Forwarded: <no|not-needed|url proving that it has been forwarded>
|
||||||
|
Reviewed-By: <name and email of someone who approved the patch>
|
||||||
|
Last-Update: 2017-08-05
|
||||||
|
|
||||||
|
--- /dev/null
|
||||||
|
+++ minifirewall-0~1708051929/PACKAGING.md
|
||||||
|
@@ -0,0 +1,4 @@
|
||||||
|
+$ git checkout debian-sid
|
||||||
|
+$ debmake -t
|
||||||
|
+... edit rules, changelog, ...
|
||||||
|
+$ dpkg-buildpackage
|
2
debian/patches/series
vendored
Normal file
2
debian/patches/series
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# You must remove unused comment lines for the released package.
|
||||||
|
add_packaging_informations
|
9
debian/rules
vendored
Executable file
9
debian/rules
vendored
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/make -f
|
||||||
|
# You must remove unused comment lines for the released package.
|
||||||
|
#export DH_VERBOSE = 1
|
||||||
|
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||||
|
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
|
||||||
|
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@
|
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3.0 (quilt)
|
2
debian/source/local-options
vendored
Normal file
2
debian/source/local-options
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#abort-on-upstream-changes
|
||||||
|
#unapply-patches
|
2
debian/watch
vendored
Normal file
2
debian/watch
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# You must remove unused comment lines for the released package.
|
||||||
|
version=3
|
1515
minifirewall
1515
minifirewall
|
@ -1,14 +1,13 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# shellcheck disable=SC2059
|
|
||||||
|
|
||||||
# minifirewall is a shell script for easy firewalling on a standalone server
|
# minifirewall is shellscripts for easy firewalling on a standalone server
|
||||||
# It uses netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
|
# we used netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
|
||||||
# See https://gitea.evolix.org/evolix/minifirewall
|
# See https://forge.evolix.org/projects/minifirewall
|
||||||
|
|
||||||
# Copyright (c) 2007-2023 Evolix
|
# Copyright (c) 2007-2015 Evolix
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 3
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License.
|
# of the License.
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
@ -18,7 +17,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: minifirewall
|
# Provides: minfirewall
|
||||||
# Required-Start:
|
# Required-Start:
|
||||||
# Required-Stop:
|
# Required-Stop:
|
||||||
# Should-Start: $network $syslog $named
|
# Should-Start: $network $syslog $named
|
||||||
|
@ -29,36 +28,16 @@
|
||||||
# Description: Firewall designed for standalone server
|
# Description: Firewall designed for standalone server
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
|
|
||||||
VERSION="23.07"
|
DESC="minifirewall"
|
||||||
|
NAME="minifirewall"
|
||||||
|
|
||||||
PROGNAME="minifirewall"
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
DESC="Firewall designed for standalone server"
|
|
||||||
|
|
||||||
set -u
|
|
||||||
|
|
||||||
if [ "$(id -u)" -ne "0" ] ; then
|
|
||||||
echo "${PROGNAME} must be run as root." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Variables configuration
|
# Variables configuration
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
config_file="/etc/default/minifirewall"
|
|
||||||
includes_dir="/etc/minifirewall.d"
|
|
||||||
|
|
||||||
# iptables paths
|
# iptables paths
|
||||||
IPT=$(command -v iptables)
|
IPT=/sbin/iptables
|
||||||
if [ -z "${IPT}" ]; then
|
IPT6=/sbin/ip6tables
|
||||||
echo "Unable to find 'iptables\` command in PATH." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
IPT6=$(command -v ip6tables)
|
|
||||||
if [ -z "${IPT6}" ]; then
|
|
||||||
echo "Unable to find 'ip6tables\` command in PATH." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TCP/IP variables
|
# TCP/IP variables
|
||||||
LOOPBACK='127.0.0.0/8'
|
LOOPBACK='127.0.0.0/8'
|
||||||
|
@ -72,1273 +51,335 @@ BROAD='255.255.255.255'
|
||||||
PORTSROOT='0:1023'
|
PORTSROOT='0:1023'
|
||||||
PORTSUSER='1024:65535'
|
PORTSUSER='1024:65535'
|
||||||
|
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
|
||||||
|
echo "Start IPTables rules..."
|
||||||
|
|
||||||
|
# Stop and warn if error!
|
||||||
|
set -e
|
||||||
|
trap 'echo "ERROR in minifirewall configuration (fix it now!) or script manipulation (fix yourself)." ' INT TERM EXIT
|
||||||
|
|
||||||
|
|
||||||
|
# sysctl network security settings
|
||||||
|
##################################
|
||||||
|
|
||||||
|
# Don't answer to broadcast pings
|
||||||
|
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
|
||||||
|
|
||||||
|
# Ignore bogus ICMP responses
|
||||||
|
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
|
||||||
|
|
||||||
|
# Disable Source Routing
|
||||||
|
for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
|
||||||
|
echo 0 > $i
|
||||||
|
done
|
||||||
|
|
||||||
|
# Enable TCP SYN cookies to avoid TCP-SYN-FLOOD attacks
|
||||||
|
# cf http://cr.yp.to/syncookies.html
|
||||||
|
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
|
||||||
|
|
||||||
|
# Disable ICMP redirects
|
||||||
|
for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
|
||||||
|
echo 0 > $i
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
|
||||||
|
echo 0 > $i
|
||||||
|
done
|
||||||
|
|
||||||
|
# Enable Reverse Path filtering : verify if responses use same network interface
|
||||||
|
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
|
||||||
|
echo 1 > $i
|
||||||
|
done
|
||||||
|
|
||||||
|
# log des paquets avec adresse incoherente
|
||||||
|
for i in /proc/sys/net/ipv4/conf/*/log_martians; do
|
||||||
|
echo 1 > $i
|
||||||
|
done
|
||||||
|
|
||||||
|
# IPTables configuration
|
||||||
|
########################
|
||||||
|
|
||||||
|
$IPT -N LOG_DROP
|
||||||
|
$IPT -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : '
|
||||||
|
$IPT -A LOG_DROP -j DROP
|
||||||
|
$IPT -N LOG_ACCEPT
|
||||||
|
$IPT -A LOG_ACCEPT -j LOG --log-prefix '[IPTABLES ACCEPT] : '
|
||||||
|
$IPT -A LOG_ACCEPT -j ACCEPT
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
oldconfigfile="/etc/firewall.rc"
|
||||||
|
configfile="/etc/default/minifirewall"
|
||||||
|
|
||||||
INT=''
|
if test -f $oldconfigfile; then
|
||||||
IPV6=''
|
echo "$oldconfigfile is deprecated, rename to $configfile" >&2
|
||||||
DOCKER=''
|
exit 1
|
||||||
INTLAN=''
|
|
||||||
TRUSTEDIPS=''
|
|
||||||
PRIVILEGIEDIPS=''
|
|
||||||
SERVICESTCP1p=''
|
|
||||||
SERVICESUDP1p=''
|
|
||||||
SERVICESTCP1=''
|
|
||||||
SERVICESUDP1=''
|
|
||||||
SERVICESTCP2=''
|
|
||||||
SERVICESUDP2=''
|
|
||||||
SERVICESTCP3=''
|
|
||||||
SERVICESUDP3=''
|
|
||||||
DNSSERVEURS=''
|
|
||||||
HTTPSITES=''
|
|
||||||
HTTPSSITES=''
|
|
||||||
FTPSITES=''
|
|
||||||
SSHOK=''
|
|
||||||
SMTPOK=''
|
|
||||||
SMTPSECUREOK=''
|
|
||||||
NTPOK=''
|
|
||||||
PROXY=''
|
|
||||||
PROXYBYPASS=''
|
|
||||||
PROXYPORT=''
|
|
||||||
BACKUPSERVERS=''
|
|
||||||
|
|
||||||
LEGACY_CONFIG='off'
|
|
||||||
|
|
||||||
STATE_FILE_LATEST='/var/run/minifirewall_state_latest'
|
|
||||||
STATE_FILE_CURRENT='/var/run/minifirewall_state_current'
|
|
||||||
STATE_FILE_PREVIOUS='/var/run/minifirewall_state_previous'
|
|
||||||
STATE_FILE_DIFF='/var/run/minifirewall_state_diff'
|
|
||||||
|
|
||||||
ACTIVE_CONFIG='/var/run/minifirewall_active_config'
|
|
||||||
ACTIVE_CONFIG_DIFF="${ACTIVE_CONFIG}.diff"
|
|
||||||
|
|
||||||
SAFETY_LOCK='/var/run/minifirewall_safety.lock'
|
|
||||||
SAFETY_OUTPUT='/var/run/minifirewall_safety.out'
|
|
||||||
SAFETY_TIMER=30
|
|
||||||
|
|
||||||
LOGGER_BIN=$(command -v logger)
|
|
||||||
|
|
||||||
# No colors by default
|
|
||||||
RED=''
|
|
||||||
GREEN=''
|
|
||||||
YELLOW=''
|
|
||||||
BLUE=''
|
|
||||||
MAGENTA=''
|
|
||||||
CYAN=''
|
|
||||||
WHITE=''
|
|
||||||
BOLD=''
|
|
||||||
RESET=''
|
|
||||||
|
|
||||||
# check if stdout is a terminal...
|
|
||||||
if [ -t 1 ]; then
|
|
||||||
INTERACTIVE=1
|
|
||||||
|
|
||||||
# see if it supports colors...
|
|
||||||
ncolors=$(tput colors)
|
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
if [ -n "${ncolors}" ] && [ ${ncolors} -ge 8 ]; then
|
|
||||||
RED=$(tput setaf 1)
|
|
||||||
GREEN=$(tput setaf 2)
|
|
||||||
YELLOW=$(tput setaf 3)
|
|
||||||
BLUE=$(tput setaf 4)
|
|
||||||
MAGENTA=$(tput setaf 5)
|
|
||||||
CYAN=$(tput setaf 6)
|
|
||||||
WHITE=$(tput setaf 7)
|
|
||||||
BOLD=$(tput bold)
|
|
||||||
RESET='\e[m'
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
INTERACTIVE=0
|
|
||||||
fi
|
fi
|
||||||
readonly INTERACTIVE
|
|
||||||
|
|
||||||
## pseudo dry-run :
|
if ! test -f $configfile; then
|
||||||
## Uncomment and call these functions instead of the real iptables and ip6tables commands
|
echo "$configfile does not exist" >&2
|
||||||
# IPT="fake_iptables"
|
exit 1
|
||||||
# IPT6="fake_ip6tables"
|
fi
|
||||||
# fake_iptables() {
|
|
||||||
# printf "DRY-RUN iptables %s\n" "$*"
|
|
||||||
# }
|
|
||||||
# fake_ip6tables() {
|
|
||||||
# printf "DRY-RUN ip6tables %s\n" "$*"
|
|
||||||
# }
|
|
||||||
## Beware that commands executed from included files are not modified by this trick.
|
|
||||||
|
|
||||||
is_interactive() {
|
|
||||||
test "${INTERACTIVE}" = "1"
|
|
||||||
}
|
|
||||||
remove_colors() {
|
|
||||||
sed -r 's/\x1B\[(;?[0-9]{1,3})+[mGK]//g'
|
|
||||||
}
|
|
||||||
syslog_info() {
|
|
||||||
if [ -x "${LOGGER_BIN}" ]; then
|
|
||||||
${LOGGER_BIN} -t "${PROGNAME}" -p daemon.info "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
syslog_error() {
|
|
||||||
if [ -x "${LOGGER_BIN}" ]; then
|
|
||||||
${LOGGER_BIN} -t "${PROGNAME}" -p daemon.error "$1"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
sort_values() {
|
|
||||||
echo "$*" | tr ' ' '\n' | sort -h
|
|
||||||
}
|
|
||||||
is_ipv6_enabled() {
|
|
||||||
test "${IPV6}" != "off"
|
|
||||||
}
|
|
||||||
is_docker_enabled() {
|
|
||||||
test "${DOCKER}" = "on"
|
|
||||||
}
|
|
||||||
is_proxy_enabled() {
|
|
||||||
test "${PROXY}" = "on"
|
|
||||||
}
|
|
||||||
is_ipv6() {
|
|
||||||
echo "$1" | grep -q ':'
|
|
||||||
}
|
|
||||||
is_legacy_config() {
|
|
||||||
test "${LEGACY_CONFIG}" != "off"
|
|
||||||
}
|
|
||||||
chain_exists() {
|
|
||||||
chain_name="$1"
|
|
||||||
if [ $# -ge 2 ]; then
|
|
||||||
intable="--table $2"
|
|
||||||
else
|
|
||||||
intable=""
|
|
||||||
fi
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
iptables ${intable} -nL "${chain_name}" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
source_file_or_error() {
|
|
||||||
file=$1
|
|
||||||
syslog_info "sourcing \`${file}'"
|
|
||||||
printf "${BLUE}sourcing \`%s'${RESET}\n" "${file}"
|
|
||||||
|
|
||||||
tmpfile=$(mktemp --tmpdir=/tmp minifirewall.XXX)
|
|
||||||
. "${file}" 2>"${tmpfile}" >&2
|
|
||||||
|
|
||||||
if [ -s "${tmpfile}" ]; then
|
|
||||||
syslog_error "Error while sourcing ${file}"
|
|
||||||
printf "${RED}%s returns standard or error output (see below). Stopping.${RESET}\n" ${file} >&2
|
|
||||||
cat "${tmpfile}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
rm -f "${tmpfile}"
|
|
||||||
}
|
|
||||||
source_configuration() {
|
|
||||||
if ! test -f ${config_file}; then
|
|
||||||
printf "${RED}%s does not exist${RESET}\n" "${config_file}" >&2
|
|
||||||
|
|
||||||
## We still want to deal with this really old configuration file
|
|
||||||
## even if it has been deprecated since Debian 8
|
|
||||||
old_config_file="/etc/firewall.rc"
|
|
||||||
if test -f ${old_config_file}; then
|
|
||||||
printf "${YELLOW}%s is deprecated and ignored. Rename it to %s${RESET}\n" "${old_config_file}" "${config_file}" >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
tmpfile=`mktemp`
|
||||||
|
. $configfile 2>$tmpfile >&2
|
||||||
|
if [ -s $tmpfile ]; then
|
||||||
|
echo "$configfile returns standard or error output (see below). Stopping." >&2
|
||||||
|
cat $tmpfile
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
rm $tmpfile
|
||||||
|
|
||||||
# If we find something other than a blank line, a comment or a variable assignment
|
# Trusted ip addresses
|
||||||
if grep --quiet --extended-regexp --invert-match "^\s*(#|$|\w+=)" "${config_file}"; then
|
$IPT -N ONLYTRUSTED
|
||||||
# Backward compatible mode
|
$IPT -A ONLYTRUSTED -j LOG_DROP
|
||||||
###########################
|
for x in $TRUSTEDIPS
|
||||||
|
do
|
||||||
printf "${YELLOW}legacy config detected${RESET}\n"
|
$IPT -I ONLYTRUSTED -s $x -j ACCEPT
|
||||||
LEGACY_CONFIG='on'
|
|
||||||
|
|
||||||
# Non-backward compatible mode
|
|
||||||
###############################
|
|
||||||
|
|
||||||
# If we ever want to remove the backward compatible mode
|
|
||||||
# we can remove the two lines above and uncomment the lines below.
|
|
||||||
# They break if any iptables/ip6tables command is found in the configuration file
|
|
||||||
|
|
||||||
# echo "iptables/ip6tables commands found in ${config_file}." >&2
|
|
||||||
# echo "Move them in included files (in ${includes_dir})." >&2
|
|
||||||
# exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if is_legacy_config; then
|
|
||||||
# In this mode, we extract all variable definitions
|
|
||||||
# to a temporary file that we can source.
|
|
||||||
# It allow iptables/ip6tables commands to remain in the configuration file
|
|
||||||
# and not interfere with the configuration step.
|
|
||||||
|
|
||||||
tmp_config_file=$(mktemp --tmpdir=/tmp minifirewall.XXX)
|
|
||||||
# get only variable assignments
|
|
||||||
grep -E "^\s*\w+=" "${config_file}" > "${tmp_config_file}"
|
|
||||||
|
|
||||||
source_file_or_error "${tmp_config_file}"
|
|
||||||
rm -f "${tmp_config_file}"
|
|
||||||
else
|
|
||||||
source_file_or_error "${config_file}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
include_files() {
|
|
||||||
if [ -d "${includes_dir}" ]; then
|
|
||||||
find ${includes_dir} -type f -readable -not -name '*.*' | sort -h
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
source_includes() {
|
|
||||||
if [ -d "${includes_dir}" ]; then
|
|
||||||
for include_file in $(include_files); do
|
|
||||||
source_file_or_error "${include_file}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
filter_config_file() {
|
|
||||||
# Remove lines with:
|
|
||||||
# * empty or only whitespaces
|
|
||||||
# * comments
|
|
||||||
grep --extended-regexp --invert-match -e "^(\s*#)" -e "^\s*$" "${1}"
|
|
||||||
}
|
|
||||||
save_active_configuration() {
|
|
||||||
dest_file=${1}
|
|
||||||
rm -f "${dest_file}"
|
|
||||||
|
|
||||||
echo "# ${config_file}" >> "${dest_file}"
|
|
||||||
filter_config_file "${config_file}" >> "${dest_file}"
|
|
||||||
|
|
||||||
found_include_files=$(include_files)
|
|
||||||
if [ -n "${found_include_files}" ]; then
|
|
||||||
for include_file in ${found_include_files}; do
|
|
||||||
echo "# ${include_file}" >> "${dest_file}"
|
|
||||||
filter_config_file "${include_file}" >> "${dest_file}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
check_active_configuration() {
|
|
||||||
# NRPE-compatible return codes
|
|
||||||
# 0: OK
|
|
||||||
# 1: WARNING
|
|
||||||
# 2: CRITICAL
|
|
||||||
# 3: UNKNOWN
|
|
||||||
rc=0
|
|
||||||
|
|
||||||
if [ -f "${ACTIVE_CONFIG}" ]; then
|
|
||||||
cmp_bin=$(command -v cmp)
|
|
||||||
diff_bin=$(command -v diff)
|
|
||||||
|
|
||||||
if [ -z "${cmp_bin}" ]; then
|
|
||||||
printf "${YELLOW}WARNING: Skipped active configuration check (Can't find cmp(1) command)${RESET}\n"
|
|
||||||
rc=1
|
|
||||||
elif [ -z "${diff_bin}" ]; then
|
|
||||||
printf "${YELLOW}WARNING: Skipped active configuration check (Can't find diff(1) command)${RESET}\n"
|
|
||||||
rc=1
|
|
||||||
else
|
|
||||||
rm -f "${ACTIVE_CONFIG_DIFF}"
|
|
||||||
|
|
||||||
tmp_config_file=$(mktemp --tmpdir=/tmp minifirewall.XXX)
|
|
||||||
save_active_configuration "${tmp_config_file}"
|
|
||||||
|
|
||||||
cmp_result=$(cmp "${ACTIVE_CONFIG}" "${tmp_config_file}" 2>&1)
|
|
||||||
cmp_rc=$?
|
|
||||||
|
|
||||||
if [ ${cmp_rc} -eq 0 ]; then
|
|
||||||
# echo " config has not changed since latest start"
|
|
||||||
printf "${GREEN}OK: Active configuration is up-to-date.${RESET}\n"
|
|
||||||
rc=0
|
|
||||||
elif [ ${cmp_rc} -eq 1 ]; then
|
|
||||||
diff -u "${ACTIVE_CONFIG}" "${tmp_config_file}" > "${ACTIVE_CONFIG_DIFF}"
|
|
||||||
|
|
||||||
printf "${RED}CRITICAL: Active configuration is not up-to-date (minifirewall not restarted after config change?), check %s${RESET}\n" "${ACTIVE_CONFIG_DIFF}"
|
|
||||||
rc=2
|
|
||||||
else
|
|
||||||
printf "${RED}CRITICAL: Error while comparing rules:${RESET}\n"
|
|
||||||
printf "${cmp_result}\n"
|
|
||||||
rc=2
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f "${tmp_config_file}"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "${YELLOW}WARNING: Skipped active configuration check (missing file ${ACTIVE_CONFIG})${RESET}\n"
|
|
||||||
rc=1
|
|
||||||
fi
|
|
||||||
exit ${rc}
|
|
||||||
}
|
|
||||||
check_unpersisted_state() {
|
|
||||||
cmp_bin=$(command -v cmp)
|
|
||||||
diff_bin=$(command -v diff)
|
|
||||||
|
|
||||||
if [ -z "${cmp_bin}" ]; then
|
|
||||||
printf "${YELLOW}skip state comparison (Can't find cmp command)${RESET}\n" >&2
|
|
||||||
elif [ -z "${diff_bin}" ]; then
|
|
||||||
printf "${YELLOW}skip state comparison (Can't find diff command)${RESET}\n" >&2
|
|
||||||
else
|
|
||||||
# store current state (without colors)
|
|
||||||
mkdir -p "$(dirname "${STATE_FILE_CURRENT}")"
|
|
||||||
status_without_numbers | remove_colors > "${STATE_FILE_CURRENT}"
|
|
||||||
|
|
||||||
# clean previous diff file
|
|
||||||
rm -f "${STATE_FILE_DIFF}"
|
|
||||||
|
|
||||||
if [ -f "${STATE_FILE_LATEST}" ]; then
|
|
||||||
cmp_result=$(cmp "${STATE_FILE_LATEST}" "${STATE_FILE_CURRENT}" 2>&1)
|
|
||||||
cmp_rc=$?
|
|
||||||
|
|
||||||
if [ ${cmp_rc} -eq 0 ]; then
|
|
||||||
# echo " rules have not changed since latest start"
|
|
||||||
:
|
|
||||||
elif [ ${cmp_rc} -eq 1 ]; then
|
|
||||||
diff -u "${STATE_FILE_LATEST}" "${STATE_FILE_CURRENT}" > "${STATE_FILE_DIFF}"
|
|
||||||
printf "${YELLOW}WARNING: current state is different than persisted state, check %s${RESET}\n" "${STATE_FILE_DIFF}" >&2
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR comparing rules:${RESET}\n" >&2
|
|
||||||
echo "${cmp_result}" >&2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
# cleanup
|
|
||||||
rm -f "${STATE_FILE_CURRENT}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
report_state_changes() {
|
|
||||||
cmp_bin=$(command -v cmp)
|
|
||||||
diff_bin=$(command -v diff)
|
|
||||||
|
|
||||||
if [ -z "${cmp_bin}" ]; then
|
|
||||||
printf "${YELLOW}skip state comparison (Can't find cmp command)${RESET}\n" >&2
|
|
||||||
return
|
|
||||||
elif [ -z "${diff_bin}" ]; then
|
|
||||||
printf "${YELLOW}skip state comparison (Can't find diff command)${RESET}\n" >&2
|
|
||||||
else
|
|
||||||
# If there is a known state
|
|
||||||
# let's compare it with the current state
|
|
||||||
if [ -f "${STATE_FILE_LATEST}" ]; then
|
|
||||||
check_unpersisted_state
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Then reset the known state (without colors)
|
|
||||||
mkdir -p "$(dirname "${STATE_FILE_LATEST}")"
|
|
||||||
status_without_numbers | remove_colors > "${STATE_FILE_LATEST}"
|
|
||||||
|
|
||||||
# But if there is a previous known state
|
|
||||||
# let's compare with the new known state
|
|
||||||
if [ -f "${STATE_FILE_PREVIOUS}" ]; then
|
|
||||||
cmp_result=$(cmp "${STATE_FILE_PREVIOUS}" "${STATE_FILE_LATEST}" 2>&1)
|
|
||||||
cmp_rc=$?
|
|
||||||
|
|
||||||
if [ ${cmp_rc} -eq 0 ]; then
|
|
||||||
# echo "Rules have not changed since previous start"
|
|
||||||
:
|
|
||||||
elif [ ${cmp_rc} -eq 1 ]; then
|
|
||||||
diff -u "${STATE_FILE_PREVIOUS}" "${STATE_FILE_LATEST}" > "${STATE_FILE_DIFF}"
|
|
||||||
printf "${YELLOW}INFO: rules have changed since latest start, check %s${RESET}\n" "${STATE_FILE_DIFF}" >&2
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR comparing rules:${RESET}\n" >&2
|
|
||||||
echo "${cmp_result}" >&2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
start() {
|
|
||||||
syslog_info "starting"
|
|
||||||
printf "${BOLD}${PROGNAME} starting${RESET}\n"
|
|
||||||
|
|
||||||
# Stop and warn if error!
|
|
||||||
set -e
|
|
||||||
trap 'printf "${RED}${PROGNAME} failed : an error occured during startup.${RESET}\n"; syslog_error "failed" ' INT TERM EXIT
|
|
||||||
|
|
||||||
# sysctl network security settings
|
|
||||||
##################################
|
|
||||||
|
|
||||||
# Set 1 to ignore broadcast pings (default)
|
|
||||||
: "${SYSCTL_ICMP_ECHO_IGNORE_BROADCASTS:=1}"
|
|
||||||
# Set 1 to ignore bogus ICMP responses (default)
|
|
||||||
: "${SYSCTL_ICMP_IGNORE_BOGUS_ERROR_RESPONSES:=1}"
|
|
||||||
# Set 0 to disable source routing (default)
|
|
||||||
: "${SYSCTL_ACCEPT_SOURCE_ROUTE:=0}"
|
|
||||||
# Set 1 to enable TCP SYN cookies (default)
|
|
||||||
# cf http://cr.yp.to/syncookies.html
|
|
||||||
: "${SYSCTL_TCP_SYNCOOKIES:=1}"
|
|
||||||
# Set 0 to disable ICMP redirects (default)
|
|
||||||
: "${SYSCTL_ICMP_REDIRECTS:=0}"
|
|
||||||
# Set 1 to enable Reverse Path filtering (default)
|
|
||||||
# Set 0 if VRRP is used
|
|
||||||
: "${SYSCTL_RP_FILTER:=1}"
|
|
||||||
# Set 1 to log packets with inconsistent address (default)
|
|
||||||
: "${SYSCTL_LOG_MARTIANS:=1}"
|
|
||||||
|
|
||||||
if [ "${SYSCTL_ICMP_ECHO_IGNORE_BROADCASTS}" = "1" ] || [ "${SYSCTL_ICMP_ECHO_IGNORE_BROADCASTS}" = "0" ]; then
|
|
||||||
echo "${SYSCTL_ICMP_ECHO_IGNORE_BROADCASTS}" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
|
|
||||||
# Apparently not applicable to IPv6
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: invalid %s value '%s', must be '0' or '1'.\n" "SYSCTL_ICMP_ECHO_IGNORE_BROADCASTS" "${SYSCTL_ICMP_ECHO_IGNORE_BROADCASTS}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${SYSCTL_ICMP_IGNORE_BOGUS_ERROR_RESPONSES}" = "1" ] || [ "${SYSCTL_ICMP_IGNORE_BOGUS_ERROR_RESPONSES}" = "0" ]; then
|
|
||||||
echo "${SYSCTL_ICMP_IGNORE_BOGUS_ERROR_RESPONSES}" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
|
|
||||||
# Apparently not applicable to IPv6
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: invalid %s value '%s', must be '0' or '1'.\n" "SYSCTL_ICMP_IGNORE_BOGUS_ERROR_RESPONSES" "${SYSCTL_ICMP_IGNORE_BOGUS_ERROR_RESPONSES}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${SYSCTL_ACCEPT_SOURCE_ROUTE}" = "1" ] || [ "${SYSCTL_ACCEPT_SOURCE_ROUTE}" = "0" ]; then
|
|
||||||
for proc_sys_file in /proc/sys/net/ipv4/conf/*/accept_source_route; do
|
|
||||||
echo "${SYSCTL_ACCEPT_SOURCE_ROUTE}" > "${proc_sys_file}"
|
|
||||||
done
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
for proc_sys_file in /proc/sys/net/ipv6/conf/*/accept_source_route; do
|
|
||||||
echo "${SYSCTL_ACCEPT_SOURCE_ROUTE}" > "${proc_sys_file}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: invalid %s value '%s', must be '0' or '1'.\n" "SYSCTL_ACCEPT_SOURCE_ROUTE" "${SYSCTL_ACCEPT_SOURCE_ROUTE}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${SYSCTL_TCP_SYNCOOKIES}" = "1" ] || [ "${SYSCTL_TCP_SYNCOOKIES}" = "0" ]; then
|
|
||||||
echo "${SYSCTL_TCP_SYNCOOKIES}" > /proc/sys/net/ipv4/tcp_syncookies
|
|
||||||
# Apparently not applicable to IPv6
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: invalid %s value '%s', must be '0' or '1'.\n" "SYSCTL_TCP_SYNCOOKIES" "${SYSCTL_TCP_SYNCOOKIES}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${SYSCTL_ICMP_REDIRECTS}" = "1" ] || [ "${SYSCTL_ICMP_REDIRECTS}" = "0" ]; then
|
|
||||||
for proc_sys_file in /proc/sys/net/ipv4/conf/*/accept_redirects; do
|
|
||||||
echo "${SYSCTL_ICMP_REDIRECTS}" > "${proc_sys_file}"
|
|
||||||
done
|
|
||||||
for proc_sys_file in /proc/sys/net/ipv4/conf/*/send_redirects; do
|
|
||||||
echo "${SYSCTL_ICMP_REDIRECTS}" > "${proc_sys_file}"
|
|
||||||
done
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
for proc_sys_file in /proc/sys/net/ipv6/conf/*/accept_redirects; do
|
|
||||||
echo "${SYSCTL_ICMP_REDIRECTS}" > "${proc_sys_file}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: invalid %s value '%s', must be '0' or '1'.\n" "SYSCTL_ICMP_REDIRECTS" "${SYSCTL_ICMP_REDIRECTS}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${SYSCTL_RP_FILTER}" = "1" ] || [ "${SYSCTL_RP_FILTER}" = "0" ]; then
|
|
||||||
for proc_sys_file in /proc/sys/net/ipv4/conf/*/rp_filter; do
|
|
||||||
echo "${SYSCTL_RP_FILTER}" > "${proc_sys_file}"
|
|
||||||
done
|
|
||||||
# Apparently not applicable to IPv6
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: invalid %s value '%s', must be '0' or '1'.\n" "SYSCTL_RP_FILTER" "${SYSCTL_RP_FILTER}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${SYSCTL_LOG_MARTIANS}" = "1" ] || [ "${SYSCTL_LOG_MARTIANS}" = "0" ]; then
|
|
||||||
for proc_sys_file in /proc/sys/net/ipv4/conf/*/log_martians; do
|
|
||||||
echo "${SYSCTL_LOG_MARTIANS}" > "${proc_sys_file}"
|
|
||||||
done
|
|
||||||
# Apparently not applicable to IPv6
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: invalid %s value '%s', must be '0' or '1'.\n" "SYSCTL_LOG_MARTIANS" "${SYSCTL_LOG_MARTIANS}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# IPTables configuration
|
|
||||||
########################
|
|
||||||
|
|
||||||
${IPT} -N LOG_DROP
|
|
||||||
${IPT} -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : '
|
|
||||||
${IPT} -A LOG_DROP -j DROP
|
|
||||||
${IPT} -N LOG_ACCEPT
|
|
||||||
${IPT} -A LOG_ACCEPT -j LOG --log-prefix '[IPTABLES ACCEPT] : '
|
|
||||||
${IPT} -A LOG_ACCEPT -j ACCEPT
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -N LOG_DROP
|
|
||||||
${IPT6} -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : '
|
|
||||||
${IPT6} -A LOG_DROP -j DROP
|
|
||||||
${IPT6} -N LOG_ACCEPT
|
|
||||||
${IPT6} -A LOG_ACCEPT -j LOG --log-prefix '[IPTABLES ACCEPT] : '
|
|
||||||
${IPT6} -A LOG_ACCEPT -j ACCEPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
if is_docker_enabled; then
|
|
||||||
${IPT} -N MINIFW-DOCKER-INPUT-MANUAL
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Source additional rules and commands
|
|
||||||
# * from legacy configuration file (/etc/default/minifirewall)
|
|
||||||
# * from configuration directory (/etc/minifirewall.d/*)
|
|
||||||
source_includes
|
|
||||||
|
|
||||||
# IP/ports lists are sorted to have consistent ordering
|
|
||||||
# You can disable this feature by simply commenting the following lines
|
|
||||||
LOOPBACK=$(sort_values ${LOOPBACK})
|
|
||||||
INTLAN=$(sort_values ${INTLAN})
|
|
||||||
TRUSTEDIPS=$(sort_values ${TRUSTEDIPS})
|
|
||||||
PRIVILEGIEDIPS=$(sort_values ${PRIVILEGIEDIPS})
|
|
||||||
SERVICESTCP1p=$(sort_values ${SERVICESTCP1p})
|
|
||||||
SERVICESUDP1p=$(sort_values ${SERVICESUDP1p})
|
|
||||||
SERVICESTCP1=$(sort_values ${SERVICESTCP1})
|
|
||||||
SERVICESUDP1=$(sort_values ${SERVICESUDP1})
|
|
||||||
SERVICESTCP2=$(sort_values ${SERVICESTCP2})
|
|
||||||
SERVICESUDP2=$(sort_values ${SERVICESUDP2})
|
|
||||||
SERVICESTCP3=$(sort_values ${SERVICESTCP3})
|
|
||||||
SERVICESUDP3=$(sort_values ${SERVICESUDP3})
|
|
||||||
DNSSERVEURS=$(sort_values ${DNSSERVEURS})
|
|
||||||
HTTPSITES=$(sort_values ${HTTPSITES})
|
|
||||||
HTTPSSITES=$(sort_values ${HTTPSSITES})
|
|
||||||
FTPSITES=$(sort_values ${FTPSITES})
|
|
||||||
SSHOK=$(sort_values ${SSHOK})
|
|
||||||
SMTPOK=$(sort_values ${SMTPOK})
|
|
||||||
SMTPSECUREOK=$(sort_values ${SMTPSECUREOK})
|
|
||||||
NTPOK=$(sort_values ${NTPOK})
|
|
||||||
PROXYBYPASS=$(sort_values ${PROXYBYPASS})
|
|
||||||
BACKUPSERVERS=$(sort_values ${BACKUPSERVERS})
|
|
||||||
|
|
||||||
# Trusted ip addresses
|
|
||||||
${IPT} -N ONLYTRUSTED
|
|
||||||
${IPT} -A ONLYTRUSTED -j LOG_DROP
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -N ONLYTRUSTED
|
|
||||||
${IPT6} -A ONLYTRUSTED -j LOG_DROP
|
|
||||||
fi
|
|
||||||
for ip in ${TRUSTEDIPS}; do
|
|
||||||
if is_ipv6 ${ip}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -I ONLYTRUSTED -s ${ip} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -I ONLYTRUSTED -s ${ip} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Privilegied ip addresses
|
# Privilegied ip addresses
|
||||||
# (trusted ip addresses *are* privilegied)
|
# (trusted ip addresses *are* privilegied)
|
||||||
${IPT} -N ONLYPRIVILEGIED
|
$IPT -N ONLYPRIVILEGIED
|
||||||
${IPT} -A ONLYPRIVILEGIED -j ONLYTRUSTED
|
$IPT -A ONLYPRIVILEGIED -j ONLYTRUSTED
|
||||||
if is_ipv6_enabled; then
|
for x in $PRIVILEGIEDIPS
|
||||||
${IPT6} -N ONLYPRIVILEGIED
|
do
|
||||||
${IPT6} -A ONLYPRIVILEGIED -j ONLYTRUSTED
|
$IPT -I ONLYPRIVILEGIED -s $x -j ACCEPT
|
||||||
fi
|
|
||||||
for ip in ${PRIVILEGIEDIPS}; do
|
|
||||||
if is_ipv6 ${ip}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -I ONLYPRIVILEGIED -s ${ip} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -I ONLYPRIVILEGIED -s ${ip} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Chain for restrictions (blacklist IPs/ranges)
|
# Chain for restrictions (blacklist IPs/ranges)
|
||||||
${IPT} -N NEEDRESTRICT
|
$IPT -N NEEDRESTRICT
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -N NEEDRESTRICT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We allow all on loopback interface
|
# We allow all on loopback interface
|
||||||
${IPT} -A INPUT -i lo -j ACCEPT
|
$IPT -A INPUT -i lo -j ACCEPT
|
||||||
if is_ipv6_enabled; then
|
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -i lo -j ACCEPT
|
||||||
${IPT6} -A INPUT -i lo -j ACCEPT
|
# if OUTPUTDROP
|
||||||
fi
|
$IPT -A OUTPUT -o lo -j ACCEPT
|
||||||
# if OUTPUTDROP
|
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -o lo -j ACCEPT
|
||||||
${IPT} -A OUTPUT -o lo -j ACCEPT
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A OUTPUT -o lo -j ACCEPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We avoid "martians" packets, typical when W32/Blaster virus
|
# We avoid "martians" packets, typical when W32/Blaster virus
|
||||||
# attacked windowsupdate.com and DNS was changed to 127.0.0.1
|
# attacked windowsupdate.com and DNS was changed to 127.0.0.1
|
||||||
# ${IPT} -t NAT -I PREROUTING -s ${LOOPBACK} -i ! lo -j DROP
|
# $IPT -t NAT -I PREROUTING -s $LOOPBACK -i ! lo -j DROP
|
||||||
for IP in ${LOOPBACK}; do
|
$IPT -A INPUT -s $LOOPBACK ! -i lo -j DROP
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -s ${IP} ! -i lo -j DROP
|
# Local services restrictions
|
||||||
fi
|
#############################
|
||||||
else
|
|
||||||
${IPT} -A INPUT -s ${IP} ! -i lo -j DROP
|
# Allow services for $INTLAN (local server or local network)
|
||||||
fi
|
$IPT -A INPUT -s $INTLAN -j ACCEPT
|
||||||
|
|
||||||
|
# Enable protection chain for sensible services
|
||||||
|
for x in $SERVICESTCP1p
|
||||||
|
do
|
||||||
|
$IPT -A INPUT -p tcp --dport $x -j NEEDRESTRICT
|
||||||
done
|
done
|
||||||
|
|
||||||
if is_docker_enabled; then
|
for x in $SERVICESUDP1p
|
||||||
# WARN: IPv6 not yet supported for Docker rules
|
do
|
||||||
${IPT} -N MINIFW-DOCKER-TRUSTED
|
$IPT -A INPUT -p udp --dport $x -j NEEDRESTRICT
|
||||||
${IPT} -A MINIFW-DOCKER-TRUSTED -j DROP
|
|
||||||
|
|
||||||
${IPT} -N MINIFW-DOCKER-PRIVILEGED
|
|
||||||
${IPT} -A MINIFW-DOCKER-PRIVILEGED -j MINIFW-DOCKER-TRUSTED
|
|
||||||
${IPT} -A MINIFW-DOCKER-PRIVILEGED -j RETURN
|
|
||||||
|
|
||||||
${IPT} -N MINIFW-DOCKER-PUB
|
|
||||||
${IPT} -A MINIFW-DOCKER-PUB -j MINIFW-DOCKER-PRIVILEGED
|
|
||||||
${IPT} -A MINIFW-DOCKER-PUB -j RETURN
|
|
||||||
|
|
||||||
# Chain MINIFW-DOCKER-INPUT-MANUAL is created earlier, to allow usage in additionnal config/command files
|
|
||||||
${IPT} -A MINIFW-DOCKER-INPUT-MANUAL -j MINIFW-DOCKER-PUB
|
|
||||||
${IPT} -A MINIFW-DOCKER-INPUT-MANUAL -j RETURN
|
|
||||||
|
|
||||||
# Flush DOCKER-USER if exist, create it if absent
|
|
||||||
if chain_exists 'DOCKER-USER'; then
|
|
||||||
${IPT} -F DOCKER-USER
|
|
||||||
else
|
|
||||||
${IPT} -N DOCKER-USER
|
|
||||||
fi;
|
|
||||||
|
|
||||||
# Pipe new connection through MINIFW-DOCKER-INPUT-MANUAL
|
|
||||||
${IPT} -A DOCKER-USER -i ${INT} -m state --state NEW -j MINIFW-DOCKER-INPUT-MANUAL
|
|
||||||
${IPT} -A DOCKER-USER -j RETURN
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Local services restrictions
|
|
||||||
#############################
|
|
||||||
|
|
||||||
# Allow services for ${INTLAN} (local server or local network)
|
|
||||||
for IP in ${INTLAN}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Enable protection chain for sensible services
|
# Public service
|
||||||
for port in ${SERVICESTCP1p}; do
|
for x in $SERVICESTCP1
|
||||||
${IPT} -A INPUT -p tcp --dport ${port} -j NEEDRESTRICT
|
do
|
||||||
if is_ipv6_enabled; then
|
$IPT -A INPUT -p tcp --dport $x -j ACCEPT
|
||||||
${IPT6} -A INPUT -p tcp --dport ${port} -j NEEDRESTRICT
|
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -p tcp --dport $x -j ACCEPT
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
for port in ${SERVICESUDP1p}; do
|
for x in $SERVICESUDP1
|
||||||
${IPT} -A INPUT -p udp --dport ${port} -j NEEDRESTRICT
|
do
|
||||||
if is_ipv6_enabled; then
|
$IPT -A INPUT -p udp --dport $x -j ACCEPT
|
||||||
${IPT6} -A INPUT -p udp --dport ${port} -j NEEDRESTRICT
|
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -p udp --dport $x -j ACCEPT
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Public service
|
# Privilegied services
|
||||||
for port in ${SERVICESTCP1}; do
|
for x in $SERVICESTCP2
|
||||||
${IPT} -A INPUT -p tcp --dport ${port} -j ACCEPT
|
do
|
||||||
if is_ipv6_enabled; then
|
$IPT -A INPUT -p tcp --dport $x -j ONLYPRIVILEGIED
|
||||||
${IPT6} -A INPUT -p tcp --dport ${port} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
for port in ${SERVICESUDP1}; do
|
for x in $SERVICESUDP2
|
||||||
${IPT} -A INPUT -p udp --dport ${port} -j ACCEPT
|
do
|
||||||
if is_ipv6_enabled; then
|
$IPT -A INPUT -p udp --dport $x -j ONLYPRIVILEGIED
|
||||||
${IPT6} -A INPUT -p udp --dport ${port} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Privilegied services
|
# Private services
|
||||||
for port in ${SERVICESTCP2}; do
|
for x in $SERVICESTCP3
|
||||||
${IPT} -A INPUT -p tcp --dport ${port} -j ONLYPRIVILEGIED
|
do
|
||||||
if is_ipv6_enabled; then
|
$IPT -A INPUT -p tcp --dport $x -j ONLYTRUSTED
|
||||||
${IPT6} -A INPUT -p tcp --dport ${port} -j ONLYPRIVILEGIED
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
for port in ${SERVICESUDP2}; do
|
for x in $SERVICESUDP3
|
||||||
${IPT} -A INPUT -p udp --dport ${port} -j ONLYPRIVILEGIED
|
do
|
||||||
if is_ipv6_enabled; then
|
$IPT -A INPUT -p udp --dport $x -j ONLYTRUSTED
|
||||||
${IPT6} -A INPUT -p udp --dport ${port} -j ONLYPRIVILEGIED
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Private services
|
|
||||||
for port in ${SERVICESTCP3}; do
|
|
||||||
${IPT} -A INPUT -p tcp --dport ${port} -j ONLYTRUSTED
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp --dport ${port} -j ONLYTRUSTED
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
for port in ${SERVICESUDP3}; do
|
|
||||||
${IPT} -A INPUT -p udp --dport ${port} -j ONLYTRUSTED
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p udp --dport ${port} -j ONLYTRUSTED
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
if is_docker_enabled; then
|
# External services
|
||||||
# WARN: IPv6 not yet supported
|
###################
|
||||||
|
|
||||||
# Public services defined in SERVICESTCP1 & SERVICESUDP1
|
# DNS authorizations
|
||||||
for dstport in ${SERVICESTCP1}; do
|
for x in $DNSSERVEURS
|
||||||
${IPT} -I MINIFW-DOCKER-PUB -p tcp --dport "${dstport}" -j RETURN
|
do
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 53 --dport $PORTSUSER -s $x -j ACCEPT
|
||||||
|
$IPT -A INPUT -p udp --sport 53 --dport $PORTSUSER -s $x -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
$IPT -A OUTPUT -o $INT -p udp -d $x --dport 53 --match state --state NEW -j ACCEPT
|
||||||
|
done
|
||||||
|
|
||||||
|
# HTTP (TCP/80) authorizations
|
||||||
|
for x in $HTTPSITES
|
||||||
|
do
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 80 --dport $PORTSUSER -s $x -j ACCEPT
|
||||||
|
done
|
||||||
|
|
||||||
|
# HTTPS (TCP/443) authorizations
|
||||||
|
for x in $HTTPSSITES
|
||||||
|
do
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 443 --dport $PORTSUSER -s $x -j ACCEPT
|
||||||
|
done
|
||||||
|
|
||||||
|
# FTP (so complex protocol...) authorizations
|
||||||
|
for x in $FTPSITES
|
||||||
|
do
|
||||||
|
# requests on Control connection
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 21 --dport $PORTSUSER -s $x -j ACCEPT
|
||||||
|
# FTP port-mode on Data Connection
|
||||||
|
$IPT -A INPUT -p tcp --sport 20 --dport $PORTSUSER -s $x -j ACCEPT
|
||||||
|
# FTP passive-mode on Data Connection
|
||||||
|
# WARNING, this allow all connections on TCP ports > 1024
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport $PORTSUSER --dport $PORTSUSER -s $x -j ACCEPT
|
||||||
|
done
|
||||||
|
|
||||||
|
# SSH authorizations
|
||||||
|
for x in $SSHOK
|
||||||
|
do
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 22 -s $x -j ACCEPT
|
||||||
done
|
done
|
||||||
|
|
||||||
for dstport in ${SERVICESUDP1}; do
|
# SMTP authorizations
|
||||||
${IPT} -I MINIFW-DOCKER-PUB -p udp --dport "${dstport}" -j RETURN
|
for x in $SMTPOK
|
||||||
|
do
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 25 --dport $PORTSUSER -j ACCEPT
|
||||||
|
done
|
||||||
|
|
||||||
|
# secure SMTP (TCP/465 et TCP/587) authorizations
|
||||||
|
for x in $SMTPSECUREOK
|
||||||
|
do
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 465 --dport $PORTSUSER -j ACCEPT
|
||||||
|
$IPT -A INPUT -p tcp ! --syn --sport 587 --dport $PORTSUSER -j ACCEPT
|
||||||
|
done
|
||||||
|
|
||||||
|
# NTP authorizations
|
||||||
|
for x in $NTPOK
|
||||||
|
do
|
||||||
|
$IPT -A INPUT -p udp --sport 123 -s $x -j ACCEPT
|
||||||
|
$IPT -A OUTPUT -o $INT -p udp -d $x --dport 123 --match state --state NEW -j ACCEPT
|
||||||
done
|
done
|
||||||
|
|
||||||
# Privileged services (accessible from privileged & trusted IPs)
|
# Always allow ICMP
|
||||||
for dstport in ${SERVICESTCP2}; do
|
$IPT -A INPUT -p icmp -j ACCEPT
|
||||||
for srcip in ${PRIVILEGIEDIPS}; do
|
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -p icmpv6 -j ACCEPT
|
||||||
if ! is_ipv6 ${srcip}; then
|
|
||||||
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p tcp -s "${srcip}" --dport "${dstport}" -j RETURN
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
for srcip in ${TRUSTEDIPS}; do
|
|
||||||
if ! is_ipv6 ${srcip}; then
|
|
||||||
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p tcp -s "${srcip}" --dport "${dstport}" -j RETURN
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
for dstport in ${SERVICESUDP2}; do
|
# IPTables policy
|
||||||
for srcip in ${PRIVILEGIEDIPS}; do
|
#################
|
||||||
if ! is_ipv6 ${srcip}; then
|
|
||||||
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p udp -s "${srcip}" --dport "${dstport}" -j RETURN
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
for srcip in ${TRUSTEDIPS}; do
|
# by default DROP INPUT packets
|
||||||
if ! is_ipv6 ${srcip}; then
|
$IPT -P INPUT DROP
|
||||||
${IPT} -I MINIFW-DOCKER-PRIVILEGED -p udp -s "${srcip}" --dport "${dstport}" -j RETURN
|
[ "$IPV6" != "off" ] && $IPT6 -P INPUT DROP
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
# Trusted services (accessible from trusted IPs)
|
# by default, no FORWARING (deprecated for Virtual Machines)
|
||||||
for dstport in ${SERVICESTCP3}; do
|
#echo 0 > /proc/sys/net/ipv4/ip_forward
|
||||||
for srcip in ${TRUSTEDIPS}; do
|
#$IPT -P FORWARD DROP
|
||||||
if ! is_ipv6 ${srcip}; then
|
#$IPT6 -P FORWARD DROP
|
||||||
${IPT} -I MINIFW-DOCKER-TRUSTED -p tcp -s "${srcip}" --dport "${dstport}" -j RETURN
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
for dstport in ${SERVICESUDP3}; do
|
# by default allow OUTPUT packets... but drop UDP packets (see OUTPUTDROP to drop OUTPUT packets)
|
||||||
for srcip in ${TRUSTEDIPS}; do
|
$IPT -P OUTPUT ACCEPT
|
||||||
if ! is_ipv6 ${srcip}; then
|
[ "$IPV6" != "off" ] && $IPT6 -P OUTPUT ACCEPT
|
||||||
${IPT} -I MINIFW-DOCKER-TRUSTED -p udp -s "${srcip}" --dport "${dstport}" -j RETURN
|
$IPT -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
||||||
fi
|
$IPT -A OUTPUT -p udp --match state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
done
|
$IPT -A OUTPUT -p udp -j DROP
|
||||||
done
|
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
||||||
fi
|
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -p udp --match state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -p udp -j DROP
|
||||||
|
|
||||||
# External services
|
trap - INT TERM EXIT
|
||||||
###################
|
|
||||||
|
|
||||||
# DNS authorizations
|
echo "...starting IPTables rules is now finish : OK"
|
||||||
for IP in ${DNSSERVEURS}; do
|
;;
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 53 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
${IPT6} -A INPUT -p udp --sport 53 --dport ${PORTSUSER} -s ${IP} -m state --state ESTABLISHED -j ACCEPT
|
|
||||||
${IPT6} -A OUTPUT -o ${INT} -p udp -d ${IP} --dport 53 --match state --state NEW -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 53 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
${IPT} -A INPUT -p udp --sport 53 --dport ${PORTSUSER} -s ${IP} -m state --state ESTABLISHED -j ACCEPT
|
|
||||||
${IPT} -A OUTPUT -o ${INT} -p udp -d ${IP} --dport 53 --match state --state NEW -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# HTTP (TCP/80) authorizations
|
stop)
|
||||||
for IP in ${HTTPSITES}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 80 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 80 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# HTTPS (TCP/443) authorizations
|
echo "Flush all rules and accept everything..."
|
||||||
for IP in ${HTTPSSITES}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 443 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 443 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# FTP (so complex protocol...) authorizations
|
|
||||||
for IP in ${FTPSITES}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
# requests on Control connection
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 21 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
# FTP port-mode on Data Connection
|
|
||||||
${IPT6} -A INPUT -p tcp --sport 20 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
# FTP passive-mode on Data Connection
|
|
||||||
# WARNING, this allow all connections on TCP ports > 1024
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport ${PORTSUSER} --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# requests on Control connection
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 21 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
# FTP port-mode on Data Connection
|
|
||||||
${IPT} -A INPUT -p tcp --sport 20 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
# FTP passive-mode on Data Connection
|
|
||||||
# WARNING, this allow all connections on TCP ports > 1024
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport ${PORTSUSER} --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# SSH authorizations
|
|
||||||
for IP in ${SSHOK}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 22 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 22 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# SMTP authorizations
|
|
||||||
for IP in ${SMTPOK}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 25 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 25 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# secure SMTP (TCP/465 et TCP/587) authorizations
|
|
||||||
for IP in ${SMTPSECUREOK}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 465 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
${IPT6} -A INPUT -p tcp ! --syn --sport 587 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 465 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
${IPT} -A INPUT -p tcp ! --syn --sport 587 --dport ${PORTSUSER} -s ${IP} -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# NTP authorizations
|
|
||||||
for IP in ${NTPOK}; do
|
|
||||||
if is_ipv6 ${IP}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p udp --sport 123 -s ${IP} -j ACCEPT
|
|
||||||
${IPT6} -A OUTPUT -o ${INT} -p udp -d ${IP} --dport 123 --match state --state NEW -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p udp --sport 123 -s ${IP} -j ACCEPT
|
|
||||||
${IPT} -A OUTPUT -o ${INT} -p udp -d ${IP} --dport 123 --match state --state NEW -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Proxy (Squid)
|
|
||||||
if is_proxy_enabled; then
|
|
||||||
# WARN: Squid only listen on IPv4 yet
|
|
||||||
# TODO: verify that the pattern used for IPv4 is relevant with IPv6
|
|
||||||
|
|
||||||
${IPT} -t nat -A OUTPUT -p tcp --dport 80 -m owner --uid-owner proxy -j ACCEPT
|
|
||||||
for dstip in ${PROXYBYPASS}; do
|
|
||||||
if ! is_ipv6 ${dstip}; then
|
|
||||||
${IPT} -t nat -A OUTPUT -p tcp --dport 80 -d "${dstip}" -j ACCEPT
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
${IPT} -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port "${PROXYPORT:-'8888'}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Output for backup servers
|
|
||||||
for server in ${BACKUPSERVERS}; do
|
|
||||||
server_port=$(echo "${server}" | awk -F : '{print $(NF)}')
|
|
||||||
server_ip=$(echo "${server}" | sed -e "s/:${server_port}$//")
|
|
||||||
|
|
||||||
if [ -n "${server_ip}" ] && [ -n "${server_port}" ]; then
|
|
||||||
if is_ipv6 ${server_ip}; then
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p tcp --sport "${server_port}" --dport 1024:65535 -s "${server_ip}" -m state --state ESTABLISHED -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
${IPT} -A INPUT -p tcp --sport "${server_port}" --dport 1024:65535 -s "${server_ip}" -m state --state ESTABLISHED -j ACCEPT
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "${RED}ERROR: unrecognized syntax for BACKUPSERVERS '%s\`. Use space-separated IP:PORT tuples.${RESET}\n" "${server}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Always allow ICMP
|
|
||||||
${IPT} -A INPUT -p icmp -j ACCEPT
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A INPUT -p icmpv6 -j ACCEPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# source config file for remaining commands
|
|
||||||
if is_legacy_config; then
|
|
||||||
source_file_or_error "${config_file}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# IPTables policy
|
|
||||||
#################
|
|
||||||
|
|
||||||
# by default DROP INPUT packets
|
|
||||||
${IPT} -P INPUT DROP
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -P INPUT DROP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# by default, no FORWARDING (deprecated for Virtual Machines)
|
|
||||||
#echo 0 > /proc/sys/net/ipv4/ip_forward
|
|
||||||
#${IPT} -P FORWARD DROP
|
|
||||||
#${IPT6} -P FORWARD DROP
|
|
||||||
|
|
||||||
# by default allow OUTPUT packets... but drop UDP packets (see OUTPUTDROP to drop OUTPUT packets)
|
|
||||||
${IPT} -P OUTPUT ACCEPT
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -P OUTPUT ACCEPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
${IPT} -A OUTPUT -o ${INT} -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A OUTPUT -o ${INT} -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
${IPT} -A OUTPUT -p udp --match state --state ESTABLISHED -j ACCEPT
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A OUTPUT -p udp --match state --state ESTABLISHED -j ACCEPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
${IPT} -A OUTPUT -p udp -j DROP
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -A OUTPUT -p udp -j DROP
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Finish
|
|
||||||
########################
|
|
||||||
|
|
||||||
trap - INT TERM EXIT
|
|
||||||
|
|
||||||
syslog_info "started"
|
|
||||||
printf "${GREEN}${BOLD}${PROGNAME} started${RESET}\n"
|
|
||||||
|
|
||||||
# No need to exit on error anymore
|
|
||||||
set +e
|
|
||||||
|
|
||||||
# save active configuration
|
|
||||||
save_active_configuration "${ACTIVE_CONFIG}"
|
|
||||||
|
|
||||||
report_state_changes
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
syslog_info "stopping"
|
|
||||||
printf "${BOLD}${PROGNAME} stopping${RESET}\n"
|
|
||||||
|
|
||||||
printf "${BLUE}flushing all rules and accepting everything${RESET}\n"
|
|
||||||
|
|
||||||
# Save previous state (without colors)
|
|
||||||
mkdir -p "$(dirname "${STATE_FILE_PREVIOUS}")"
|
|
||||||
status_without_numbers | remove_colors > "${STATE_FILE_PREVIOUS}"
|
|
||||||
|
|
||||||
# Delete all rules
|
# Delete all rules
|
||||||
${IPT} -F INPUT
|
$IPT -F INPUT
|
||||||
if is_ipv6_enabled; then
|
$IPT -F OUTPUT
|
||||||
${IPT6} -F INPUT
|
$IPT -F LOG_DROP
|
||||||
fi
|
$IPT -F LOG_ACCEPT
|
||||||
|
$IPT -F ONLYTRUSTED
|
||||||
${IPT} -F OUTPUT
|
$IPT -F ONLYPRIVILEGIED
|
||||||
if is_ipv6_enabled; then
|
$IPT -F NEEDRESTRICT
|
||||||
${IPT6} -F OUTPUT
|
$IPT -t nat -F
|
||||||
fi
|
$IPT -t mangle -F
|
||||||
|
[ "$IPV6" != "off" ] && $IPT6 -F INPUT
|
||||||
${IPT} -F LOG_DROP
|
[ "$IPV6" != "off" ] && $IPT6 -F OUTPUT
|
||||||
${IPT} -F LOG_ACCEPT
|
|
||||||
${IPT} -F ONLYTRUSTED
|
|
||||||
${IPT} -F ONLYPRIVILEGIED
|
|
||||||
${IPT} -F NEEDRESTRICT
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -F LOG_DROP
|
|
||||||
${IPT6} -F LOG_ACCEPT
|
|
||||||
${IPT6} -F ONLYTRUSTED
|
|
||||||
${IPT6} -F ONLYPRIVILEGIED
|
|
||||||
${IPT6} -F NEEDRESTRICT
|
|
||||||
fi
|
|
||||||
|
|
||||||
${IPT} -t mangle -F
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -t mangle -F
|
|
||||||
fi
|
|
||||||
|
|
||||||
if is_docker_enabled; then
|
|
||||||
# WARN: IPv6 not yet supported
|
|
||||||
|
|
||||||
${IPT} -F DOCKER-USER
|
|
||||||
${IPT} -A DOCKER-USER -j RETURN
|
|
||||||
|
|
||||||
${IPT} -F MINIFW-DOCKER-INPUT-MANUAL
|
|
||||||
${IPT} -X MINIFW-DOCKER-INPUT-MANUAL
|
|
||||||
${IPT} -F MINIFW-DOCKER-PUB
|
|
||||||
${IPT} -X MINIFW-DOCKER-PUB
|
|
||||||
${IPT} -F MINIFW-DOCKER-PRIVILEGED
|
|
||||||
${IPT} -X MINIFW-DOCKER-PRIVILEGED
|
|
||||||
${IPT} -F MINIFW-DOCKER-TRUSTED
|
|
||||||
${IPT} -X MINIFW-DOCKER-TRUSTED
|
|
||||||
else
|
|
||||||
${IPT} -t nat -F
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Accept all
|
# Accept all
|
||||||
${IPT} -P INPUT ACCEPT
|
$IPT -P INPUT ACCEPT
|
||||||
if is_ipv6_enabled; then
|
$IPT -P OUTPUT ACCEPT
|
||||||
${IPT6} -P INPUT ACCEPT
|
[ "$IPV6" != "off" ] && $IPT6 -P INPUT ACCEPT
|
||||||
fi
|
[ "$IPV6" != "off" ] && $IPT6 -P OUTPUT ACCEPT
|
||||||
|
#$IPT -P FORWARD ACCEPT
|
||||||
${IPT} -P OUTPUT ACCEPT
|
#$IPT -t nat -P PREROUTING ACCEPT
|
||||||
if is_ipv6_enabled; then
|
#$IPT -t nat -P POSTROUTING ACCEPT
|
||||||
${IPT6} -P OUTPUT ACCEPT
|
|
||||||
fi
|
|
||||||
#${IPT} -P FORWARD ACCEPT
|
|
||||||
#${IPT} -t nat -P PREROUTING ACCEPT
|
|
||||||
#${IPT} -t nat -P POSTROUTING ACCEPT
|
|
||||||
|
|
||||||
# Delete non-standard chains
|
# Delete non-standard chains
|
||||||
${IPT} -X LOG_DROP
|
$IPT -X LOG_DROP
|
||||||
${IPT} -X LOG_ACCEPT
|
$IPT -X LOG_ACCEPT
|
||||||
${IPT} -X ONLYPRIVILEGIED
|
$IPT -X ONLYPRIVILEGIED
|
||||||
${IPT} -X ONLYTRUSTED
|
$IPT -X ONLYTRUSTED
|
||||||
${IPT} -X NEEDRESTRICT
|
$IPT -X NEEDRESTRICT
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -X LOG_DROP
|
|
||||||
${IPT6} -X LOG_ACCEPT
|
|
||||||
${IPT6} -X ONLYPRIVILEGIED
|
|
||||||
${IPT6} -X ONLYTRUSTED
|
|
||||||
${IPT6} -X NEEDRESTRICT
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f "${STATE_FILE_LATEST}" "${STATE_FILE_CURRENT}" "${ACTIVE_CONFIG}"
|
echo "...flushing IPTables rules is now finish : OK"
|
||||||
|
;;
|
||||||
|
|
||||||
syslog_info "stopped"
|
status)
|
||||||
printf "${GREEN}${BOLD}${PROGNAME} stopped${RESET}\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
status() {
|
$IPT -L -n -v --line-numbers
|
||||||
printf "${BLUE}#### iptables --list ###############################${RESET}\n"
|
$IPT -t nat -L -n -v --line-numbers
|
||||||
${IPT} --list --numeric --verbose --line-numbers
|
$IPT -t mangle -L -n -v --line-numbers
|
||||||
printf "\n${BLUE}#### iptables --table nat --list ###################${RESET}\n"
|
$IPT6 -L -n -v --line-numbers
|
||||||
${IPT} --table nat --list --numeric --verbose --line-numbers
|
$IPT6 -t mangle -L -n -v --line-numbers
|
||||||
printf "\n${BLUE}#### iptables --table mangle --list ################${RESET}\n"
|
;;
|
||||||
${IPT} --table mangle --list --numeric --verbose --line-numbers
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
printf "\n${BLUE}#### ip6tables --list ##############################${RESET}\n"
|
|
||||||
${IPT6} --list --numeric --verbose --line-numbers
|
|
||||||
printf "\n${BLUE}#### ip6tables --table mangle --list ###############${RESET}\n"
|
|
||||||
${IPT6} --table mangle --list --numeric --verbose --line-numbers
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
status_without_numbers() {
|
reset)
|
||||||
printf "${BLUE}#### iptables --list ###############################${RESET}\n"
|
|
||||||
${IPT} --list --numeric
|
|
||||||
printf "\n${BLUE}#### iptables --table nat --list ###################${RESET}\n"
|
|
||||||
${IPT} --table nat --list --numeric
|
|
||||||
printf "\n${BLUE}#### iptables --table mangle --list ################${RESET}\n"
|
|
||||||
${IPT} --table mangle --list --numeric
|
|
||||||
if is_ipv6_enabled; then
|
|
||||||
printf "\n${BLUE}#### ip6tables --list ##############################${RESET}\n"
|
|
||||||
${IPT6} --list --numeric
|
|
||||||
printf "\n${BLUE}#### ip6tables --table mangle --list ###############${RESET}\n"
|
|
||||||
${IPT6} --table mangle --list --numeric
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
reset() {
|
echo "Reset all IPTables counters..."
|
||||||
syslog_info "resetting"
|
|
||||||
printf "${BOLD}${PROGNAME} resetting${RESET}\n"
|
|
||||||
|
|
||||||
${IPT} -Z
|
$IPT -Z
|
||||||
if is_ipv6_enabled; then
|
$IPT -t nat -Z
|
||||||
${IPT6} -Z
|
$IPT -t mangle -Z
|
||||||
fi
|
[ "$IPV6" != "off" ] && $IPT6 -Z
|
||||||
|
[ "$IPV6" != "off" ] && $IPT6 -t mangle -Z
|
||||||
|
|
||||||
${IPT} -t nat -Z
|
echo "...reseting IPTables counters is now finish : OK"
|
||||||
|
;;
|
||||||
|
|
||||||
${IPT} -t mangle -Z
|
restart)
|
||||||
if is_ipv6_enabled; then
|
|
||||||
${IPT6} -t mangle -Z
|
|
||||||
fi
|
|
||||||
|
|
||||||
syslog_info "reset"
|
$0 stop
|
||||||
printf "${GREEN}${BOLD}${PROGNAME} reset${RESET}\n"
|
$0 start
|
||||||
}
|
;;
|
||||||
|
|
||||||
safety_timer() {
|
*)
|
||||||
if [ "${SAFETY_TIMER}" -le "0" ] || [ "${SAFETY_TIMER}" -gt "3600" ]; then
|
|
||||||
syslog_info "safety timer value '${SAFETY_TIMER}' is out of range (1 < 3600), reverted to default value of '30'."
|
|
||||||
SAFETY_TIMER=30
|
|
||||||
readonly SAFETY_TIMER
|
|
||||||
fi
|
|
||||||
echo "${SAFETY_TIMER}"
|
|
||||||
}
|
|
||||||
|
|
||||||
stop_if_locked() {
|
echo "Usage: $0 {start|stop|restart|status|reset|squid}"
|
||||||
count=0
|
exit 1
|
||||||
|
|
||||||
while [ "${count}" -lt "$(safety_timer)" ] && [ -f "${SAFETY_LOCK}" ]; do
|
|
||||||
count=$(( count + 1 ))
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -f "${SAFETY_LOCK}" ]; then
|
|
||||||
syslog_error "safety lock is still here after $(safety_timer) seconds, we need to stop"
|
|
||||||
|
|
||||||
stop
|
|
||||||
|
|
||||||
syslog_info "remove safety lock"
|
|
||||||
rm -f "${SAFETY_LOCK}"
|
|
||||||
else
|
|
||||||
syslog_info "safety lock is not there anymore, life goes on"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
safe_start() {
|
|
||||||
# start the firewall
|
|
||||||
start
|
|
||||||
|
|
||||||
# create the lock file
|
|
||||||
syslog_info "add safety lock"
|
|
||||||
touch "${SAFETY_LOCK}"
|
|
||||||
|
|
||||||
# run the special background command
|
|
||||||
nohup "${0}" stop-if-locked > "${SAFETY_OUTPUT}" 2>&1 &
|
|
||||||
|
|
||||||
if is_interactive; then
|
|
||||||
syslog_info "safe-restart in interactive mode ; if safety lock (${SAFETY_LOCK}) is not removed in the next $(safety_timer) seconds, minifirewall will be stopped."
|
|
||||||
# Ask for input
|
|
||||||
confirm_default="I'm locked out, please stop the firewall"
|
|
||||||
# printf "If the restart has locked you out you might see this but you shouldn't be able to type anything.\n"
|
|
||||||
printf "Minifirewall will be stopped in $(safety_timer) seconds if you do nothing.\n"
|
|
||||||
printf "Remove \`${SAFETY_LOCK}' or type anything to keep minifirewall started: "
|
|
||||||
|
|
||||||
read -r confirm
|
|
||||||
|
|
||||||
if [ ! -f "${SAFETY_LOCK}" ]; then
|
|
||||||
printf "${YELLOW}Safety lock is not there anymore.\nYou've probably been rescued by the safety checks.\n${BOLD}Minifirewall is probably stopped.${RESET}\n"
|
|
||||||
elif [ "${confirm}" != "${confirm_default}" ]; then
|
|
||||||
rm -f "${SAFETY_LOCK}" && printf "${GREEN}OK. Safety lock is removed.${RESET}\n"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
syslog_info "safe-restart in non-interactive mode ; if safety lock (${SAFETY_LOCK}) is not removed in the next $(safety_timer) seconds, minifirewall will be stopped."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
show_version() {
|
|
||||||
cat <<END
|
|
||||||
${PROGNAME} version ${VERSION}
|
|
||||||
|
|
||||||
Copyright 2007-2023 Evolix <info@evolix.fr>.
|
|
||||||
|
|
||||||
${PROGNAME} comes with ABSOLUTELY NO WARRANTY.
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License
|
|
||||||
as published by the Free Software Foundation; either version 3
|
|
||||||
of the License.
|
|
||||||
END
|
|
||||||
}
|
|
||||||
show_help() {
|
|
||||||
cat <<END
|
|
||||||
${PROGNAME} ${DESC}
|
|
||||||
|
|
||||||
END
|
|
||||||
show_usage
|
|
||||||
}
|
|
||||||
show_usage() {
|
|
||||||
cat <<END
|
|
||||||
Usage: ${PROGNAME} [COMMAND]
|
|
||||||
|
|
||||||
Commands
|
|
||||||
start Start minifirewall
|
|
||||||
safe-start Start minifirewall, with baground safety checks
|
|
||||||
stop Stop minifirewall
|
|
||||||
restart Stop then start minifirewall
|
|
||||||
safe-restart Restart minifirewall, with background safety checks
|
|
||||||
status Print minifirewall status
|
|
||||||
reset Reset iptables tables
|
|
||||||
check-active-config Check if active config is up-to-date with stored config
|
|
||||||
version Print version and exit
|
|
||||||
help Print this message and exit
|
|
||||||
END
|
|
||||||
}
|
|
||||||
|
|
||||||
case "${1:-''}" in
|
|
||||||
start)
|
|
||||||
source_configuration
|
|
||||||
check_unpersisted_state
|
|
||||||
|
|
||||||
start
|
|
||||||
;;
|
|
||||||
|
|
||||||
safe-start)
|
|
||||||
source_configuration
|
|
||||||
check_unpersisted_state
|
|
||||||
|
|
||||||
safe_start
|
|
||||||
;;
|
|
||||||
|
|
||||||
stop)
|
|
||||||
source_configuration
|
|
||||||
check_unpersisted_state
|
|
||||||
|
|
||||||
stop
|
|
||||||
;;
|
|
||||||
|
|
||||||
status)
|
|
||||||
source_configuration
|
|
||||||
check_unpersisted_state
|
|
||||||
|
|
||||||
status
|
|
||||||
;;
|
|
||||||
|
|
||||||
reset)
|
|
||||||
source_configuration
|
|
||||||
check_unpersisted_state
|
|
||||||
|
|
||||||
reset
|
|
||||||
;;
|
|
||||||
|
|
||||||
restart)
|
|
||||||
source_configuration
|
|
||||||
check_unpersisted_state
|
|
||||||
|
|
||||||
stop
|
|
||||||
start
|
|
||||||
;;
|
|
||||||
|
|
||||||
safe-restart)
|
|
||||||
source_configuration
|
|
||||||
check_unpersisted_state
|
|
||||||
|
|
||||||
stop
|
|
||||||
safe_start
|
|
||||||
;;
|
|
||||||
|
|
||||||
stop-if-locked)
|
|
||||||
source_configuration
|
|
||||||
|
|
||||||
stop_if_locked
|
|
||||||
;;
|
|
||||||
|
|
||||||
check-active-config)
|
|
||||||
check_active_configuration
|
|
||||||
;;
|
|
||||||
|
|
||||||
version)
|
|
||||||
show_version
|
|
||||||
;;
|
|
||||||
|
|
||||||
help)
|
|
||||||
show_help
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
printf "%s: %s: unknown option\n" "${PROGNAME}" "${1}"
|
|
||||||
show_usage
|
|
||||||
exit 128
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
|
@ -1,136 +1,96 @@
|
||||||
# Configuration for minifirewall : https://gitea.evolix.org/evolix/minifirewall
|
# Configuration for minifirewall : https://forge.evolix.org/projects/minifirewall
|
||||||
# Version 23.07
|
# For fun, we keep last change from first CVS repository:
|
||||||
# shellcheck shell=sh disable=SC2034
|
# version 0.1 - 12 juillet 2007 $Id: firewall.rc,v 1.2 2007/07/12 19:08:59 reg Exp $
|
||||||
|
|
||||||
# Main interface
|
# Main interface
|
||||||
INT='eth0'
|
INT='eth0'
|
||||||
|
|
||||||
# IPv6
|
# IPv6
|
||||||
IPV6='on'
|
IPV6=on
|
||||||
|
|
||||||
# Docker Mode
|
# Trusted IPv4 local network
|
||||||
# Changes the behaviour of minifirewall to not break the containers' network
|
# ...will be often IP/32 if you don't trust anything
|
||||||
# For instance, turning it on will disable nat table purge
|
INTLAN='192.168.0.2/32'
|
||||||
# Also, we'll add the DOCKER-USER chain, in iptables
|
|
||||||
#
|
|
||||||
# WARNING : If the port mapping is different between the host and the container
|
|
||||||
# (ie: Listen on :8090 on host, but :8080 in container)
|
|
||||||
# then you need to give the port used inside the container
|
|
||||||
DOCKER='off'
|
|
||||||
|
|
||||||
# Trusted local network
|
# Trusted IPv4 addresses for private and semi-public services
|
||||||
# ...will be often IPv4/32 or IPv6/128 if you don't trust anything
|
TRUSTEDIPS='62.212.121.90 88.179.18.233 31.170.8.4 31.170.9.129'
|
||||||
INTLAN='192.0.2.1/32 2001:db8::1/128'
|
|
||||||
|
|
||||||
# Trusted IP addresses for private and semi-public services
|
# Privilegied IPv4 addresses for semi-public services
|
||||||
# TODO: add all our IPv6 adresses
|
|
||||||
TRUSTEDIPS='31.170.9.129 2a01:9500:37:129::/64 31.170.8.4 2a01:9500::fada 82.65.34.85 2a01:e0a:571:2a10::1 54.37.106.210 51.210.84.146'
|
|
||||||
|
|
||||||
# Privilegied IP addresses for semi-public services
|
|
||||||
# (no need to add again TRUSTEDIPS)
|
# (no need to add again TRUSTEDIPS)
|
||||||
PRIVILEGIEDIPS=''
|
PRIVILEGIEDIPS=''
|
||||||
|
|
||||||
|
|
||||||
# Local services IP restrictions
|
# Local services IPv4/IPv6 restrictions
|
||||||
#######################################
|
#######################################
|
||||||
|
|
||||||
# Protected services
|
# Protected services
|
||||||
# (add also in Public services if needed)
|
# (add also in Public services if needed)
|
||||||
SERVICESTCP1p='22222'
|
SERVICESTCP1p='22'
|
||||||
SERVICESUDP1p=''
|
SERVICESUDP1p=''
|
||||||
|
|
||||||
# Public services (IPv4/IPv6)
|
# Public services (IPv4/IPv6)
|
||||||
SERVICESTCP1='22222'
|
SERVICESTCP1='25 53 443 993 995 2222'
|
||||||
SERVICESUDP1=''
|
SERVICESUDP1='53'
|
||||||
|
|
||||||
# Semi-public services (IPv4)
|
# Semi-public services (IPv4)
|
||||||
SERVICESTCP2='22'
|
SERVICESTCP2='20 21 22 80 110 143'
|
||||||
SERVICESUDP2=''
|
SERVICESUDP2=''
|
||||||
|
|
||||||
# Private services (IPv4)
|
# Private services (IPv4)
|
||||||
SERVICESTCP3='5666'
|
SERVICESTCP3='5666'
|
||||||
SERVICESUDP3=''
|
SERVICESUDP3=''
|
||||||
|
|
||||||
|
# Standard output IPv4 access restrictions
|
||||||
# Standard output IPv4/IPv6 access restrictions
|
|
||||||
##########################################
|
##########################################
|
||||||
|
|
||||||
# DNS authorizations
|
# DNS authorizations
|
||||||
# (if you have local DNS server, set 0.0.0.0/0)
|
# (if you have local DNS server, set 0.0.0.0/0)
|
||||||
DNSSERVEURS='0.0.0.0/0 ::/0'
|
DNSSERVEURS='0.0.0.0/0'
|
||||||
|
|
||||||
# HTTP authorizations
|
# HTTP authorizations
|
||||||
# (you can use DNS names but set cron to reload minifirewall regularly)
|
# (you can use DNS names but set cron to reload minifirewall regularly)
|
||||||
# (if you have HTTP proxy, set 0.0.0.0/0)
|
# (if you have HTTP proxy, set 0.0.0.0/0)
|
||||||
HTTPSITES='0.0.0.0/0 ::/0'
|
HTTPSITES='security.debian.org pub.evolix.net volatile.debian.org mirror.evolix.org backports.debian.org hwraid.le-vert.net antispam00.evolix.org spamassassin.apache.org sa-update.space-pro.be sa-update.secnap.net www.sa-update.pccc.com sa-update.dnswl.org ocsp.int-x3.letsencrypt.org'
|
||||||
|
|
||||||
# HTTPS authorizations
|
# HTTPS authorizations
|
||||||
HTTPSSITES='0.0.0.0/0 ::/0'
|
HTTPSSITES='0.0.0.0/0'
|
||||||
|
|
||||||
# FTP authorizations
|
# FTP authorizations
|
||||||
FTPSITES=''
|
FTPSITES=''
|
||||||
|
|
||||||
# SSH authorizations
|
# SSH authorizations
|
||||||
SSHOK='0.0.0.0/0 ::/0'
|
SSHOK='0.0.0.0/0'
|
||||||
|
|
||||||
# SMTP authorizations
|
# SMTP authorizations
|
||||||
SMTPOK='0.0.0.0/0 ::/0'
|
SMTPOK='0.0.0.0/0'
|
||||||
|
|
||||||
# SMTP secure authorizations (ports TCP/465 and TCP/587)
|
# SMTP secure authorizations (ports TCP/465 and TCP/587)
|
||||||
SMTPSECUREOK=''
|
SMTPSECUREOK=''
|
||||||
|
|
||||||
# NTP authorizations
|
# NTP authorizations
|
||||||
NTPOK='0.0.0.0/0 ::/0'
|
NTPOK='0.0.0.0/0'
|
||||||
|
|
||||||
# Proxy (Squid)
|
|
||||||
PROXY='off'
|
|
||||||
# (proxy port)
|
|
||||||
PROXYPORT='8888'
|
|
||||||
# (destinations that bypass the proxy)
|
|
||||||
PROXYBYPASS="${INTLAN} 127.0.0.0/8 ::1/128"
|
|
||||||
|
|
||||||
# Backup servers
|
|
||||||
# (add IP:PORT for each one, example: '192.168.10.1:1234 192.168.10.2:5678')
|
|
||||||
BACKUPSERVERS=''
|
|
||||||
|
|
||||||
|
|
||||||
# Includes
|
# IPv6 Specific rules
|
||||||
#####################
|
#####################
|
||||||
|
|
||||||
# Files in /etc/minifirewall.d/* (without "." in name)
|
# Example: allow input HTTP/HTTPS/SMTP/DNS traffic
|
||||||
# are automatically included in alphanumerical order.
|
/sbin/ip6tables -A INPUT -i $INT -p tcp --sport 80 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
#
|
/sbin/ip6tables -A INPUT -i $INT -p tcp --sport 443 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
# Within included files, you can use those helper functions :
|
/sbin/ip6tables -A INPUT -i $INT -p tcp --sport 25 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
# * is_ipv6_enabled: returns true if IPv6 is enabled, or false
|
/sbin/ip6tables -A INPUT -i $INT -p udp --sport 53 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
# * is_docker_enabled: returns true if Docker mode is eabled, or false
|
/sbin/ip6tables -A INPUT -i $INT -p tcp --sport 53 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
# * is_proxy_enabled: returns true if Proxy mode is enabled , or false
|
|
||||||
|
|
||||||
|
# Example: allow output DNS, NTP and traceroute traffic
|
||||||
|
/sbin/ip6tables -A OUTPUT -o $INT -p udp --dport 53 --match state --state NEW -j ACCEPT
|
||||||
|
/sbin/ip6tables -A OUTPUT -o $INT -p udp --dport 123 --match state --state NEW -j ACCEPT
|
||||||
|
#/sbin/ip6tables -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
||||||
|
|
||||||
# Custom sysctl values (advanced)
|
# Example: allow DHCPv6
|
||||||
#################################
|
/sbin/ip6tables -A INPUT -i $INT -p udp --dport 546 -d fe80::/64 -j ACCEPT
|
||||||
|
/sbin/ip6tables -A OUTPUT -o $INT -p udp --dport 547 -j ACCEPT
|
||||||
|
|
||||||
# In most cases, the default values set by minifirewall are good.
|
# IPv4 Specific rules
|
||||||
# If you really know what you are doing,
|
#####################
|
||||||
# you can uncomment some lines and customize the values.
|
|
||||||
|
|
||||||
# Set 1 to ignore broadcast pings (default)
|
# /sbin/iptables ...
|
||||||
# SYSCTL_ICMP_ECHO_IGNORE_BROADCASTS='1'
|
|
||||||
|
|
||||||
# Set 1 to ignore bogus ICMP responses (default)
|
|
||||||
# SYSCTL_ICMP_IGNORE_BOGUS_ERROR_RESPONSES='1'
|
|
||||||
|
|
||||||
# Set 0 to disable source routing (default)
|
|
||||||
# SYSCTL_ACCEPT_SOURCE_ROUTE='0'
|
|
||||||
|
|
||||||
# Set 1 to enable TCP SYN cookies (default)
|
|
||||||
# SYSCTL_TCP_SYNCOOKIES='1'
|
|
||||||
|
|
||||||
# Set 0 to disable ICMP redirects (default)
|
|
||||||
# SYSCTL_ICMP_REDIRECTS='0'
|
|
||||||
|
|
||||||
# Set 1 to enable Reverse Path filtering (default)
|
|
||||||
# Set 0 if VRRP is used
|
|
||||||
# SYSCTL_RP_FILTER='1'
|
|
||||||
|
|
||||||
# Set 1 to log packets with inconsistent address (default)
|
|
||||||
# SYSCTL_LOG_MARTIANS='1'
|
|
||||||
|
|
|
@ -1,136 +0,0 @@
|
||||||
# Fichier de configuration
|
|
||||||
# pour minifirewall
|
|
||||||
|
|
||||||
# version 0.1 - 12 juillet 2007 $Id: firewall.rc,v 1.2 2007/07/12 19:08:59 reg Exp $
|
|
||||||
|
|
||||||
# Interface concernee
|
|
||||||
INT='eth0.11'
|
|
||||||
|
|
||||||
IPV6=on
|
|
||||||
|
|
||||||
# IP associee (plus utilisee dans les scripts)
|
|
||||||
# INTIP='192.168.0.2'
|
|
||||||
# reseau beneficiant d'acces privilegies
|
|
||||||
# (sera souvent IP/32)
|
|
||||||
INTLAN='192.0.2.1/32'
|
|
||||||
|
|
||||||
# trusted ip addresses
|
|
||||||
TRUSTEDIPS='62.212.121.90 62.212.111.216 88.179.18.233 85.118.59.4 85.118.59.50 31.170.8.4 31.170.9.129 82.65.34.85 54.37.106.210 51.210.84.146'
|
|
||||||
|
|
||||||
# privilegied ip addresses
|
|
||||||
# (trusted ip addresses *are* privilegied)
|
|
||||||
PRIVILEGIEDIPS='80.14.117.69 31.170.8.6 31.170.11.167 31.170.11.167 31.170.8.7 31.170.8.249 31.170.8.76 31.170.8.222 80.245.23.179 51.38.233.228'
|
|
||||||
|
|
||||||
# Services "protected"
|
|
||||||
# a mettre aussi en public si necessaire !!
|
|
||||||
SERVICESTCP1p=''
|
|
||||||
SERVICESUDP1p=''
|
|
||||||
|
|
||||||
# Services "publics"
|
|
||||||
SERVICESTCP1='21 80 443 2222'
|
|
||||||
SERVICESUDP1=''
|
|
||||||
|
|
||||||
# Services "semi-publics"
|
|
||||||
SERVICESTCP2='20 22 25'
|
|
||||||
SERVICESUDP2=''
|
|
||||||
|
|
||||||
# Services "prives"
|
|
||||||
SERVICESTCP3='5666'
|
|
||||||
SERVICESUDP3=''
|
|
||||||
|
|
||||||
################### SORTANTS
|
|
||||||
|
|
||||||
# DNS
|
|
||||||
# (Attention, si un serveur DNS est installe en local
|
|
||||||
# mettre 0.0.0.0/0)
|
|
||||||
DNSSERVEURS='0.0.0.0/0'
|
|
||||||
|
|
||||||
# HTTP : security.d.o x3, zidane, modsecurity www.debian.org
|
|
||||||
# /!\ Possibilite d'utiliser des noms de domaines
|
|
||||||
# mais il est conseiller de placer un rechargement
|
|
||||||
# du minifirewall en crontab
|
|
||||||
# (Attention, si un proxy HTTP est installe en local
|
|
||||||
# mettre 0.0.0.0/0)
|
|
||||||
HTTPSITES='0.0.0.0/0'
|
|
||||||
|
|
||||||
# HTTPS
|
|
||||||
# /!\ Possibilite d'utiliser des noms de domaines
|
|
||||||
# mais il est conseiller de placer un rechargement
|
|
||||||
# du minifirewall en crontab
|
|
||||||
HTTPSSITES='0.0.0.0/0'
|
|
||||||
|
|
||||||
# FTP
|
|
||||||
FTPSITES='0.0.0.0/0'
|
|
||||||
|
|
||||||
# SSH
|
|
||||||
SSHOK='0.0.0.0/0'
|
|
||||||
|
|
||||||
# SMTP
|
|
||||||
SMTPOK='0.0.0.0/0'
|
|
||||||
|
|
||||||
# SMTP secure (port 465 et 587)
|
|
||||||
SMTPSECUREOK='0.0.0.0/0'
|
|
||||||
|
|
||||||
# NTP
|
|
||||||
NTPOK='0.0.0.0/0'
|
|
||||||
|
|
||||||
################### IPv6 Specific rules
|
|
||||||
# /sbin/ip6tables ...
|
|
||||||
|
|
||||||
# Allow HTTP/HTTPS/SMTP traffic
|
|
||||||
/sbin/ip6tables -A INPUT -i $INT -p tcp --sport 80 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/ip6tables -A INPUT -i $INT -p tcp --sport 443 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/ip6tables -A INPUT -i $INT -p tcp --sport 25 --match state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
|
|
||||||
# Allow DNS, NTP and traceroute traffic
|
|
||||||
/sbin/ip6tables -A OUTPUT -o $INT -p udp --dport 53 --match state --state NEW -j ACCEPT
|
|
||||||
/sbin/ip6tables -A OUTPUT -o $INT -p udp --dport 123 --match state --state NEW -j ACCEPT
|
|
||||||
/sbin/ip6tables -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
|
||||||
|
|
||||||
# Allow DHCPv6
|
|
||||||
/sbin/ip6tables -t filter -A INPUT -i $INT -p udp --dport 546 -d fe80::/64 -j ACCEPT
|
|
||||||
/sbin/ip6tables -t filter -A OUTPUT -o $INT -p udp --dport 547 -j ACCEPT
|
|
||||||
|
|
||||||
################### IPv4 Specific rules
|
|
||||||
# /sbin/iptables ...
|
|
||||||
|
|
||||||
# Allow DNS, NTP and traceroute traffic
|
|
||||||
/sbin/iptables -A OUTPUT -o $INT -p udp --dport 53 --match state --state NEW -j ACCEPT
|
|
||||||
/sbin/iptables -A OUTPUT -o $INT -p udp --dport 123 --match state --state NEW -j ACCEPT
|
|
||||||
/sbin/iptables -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
|
||||||
|
|
||||||
# EvoBackup
|
|
||||||
# /sbin/iptables -A INPUT -p tcp --sport XXXX --dport 1024:65535 -s 85.118.59.1 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
# /sbin/iptables -A INPUT -p tcp --sport XXXX --dport 1024:65535 -s 31.170.8.1 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
# /sbin/iptables -A INPUT -p tcp --sport XXXX --dport 1024:65535 -s 178.32.100.48 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 2223 --dport 1024:65535 -s 62.210.209.17 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
|
|
||||||
# FTP en mode passif
|
|
||||||
/sbin/iptables -A INPUT -p tcp --dport 60000:61000 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
|
|
||||||
# EvoMaintenance
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 5432 --dport 1024:65535 -s 31.170.8.4 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 5432 --dport 1024:65535 -s 62.212.121.90 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 5432 --dport 1024:65535 -s 62.212.111.216 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 5432 --dport 1024:65535 -s 88.179.18.233 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 5432 --dport 1024:65535 -s 85.118.59.50 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 5432 --dport 1024:65535 -s 31.170.9.129 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
|
|
||||||
# Proxy
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner --uid-owner proxy -j ACCEPT
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -d 31.170.8.7 -j ACCEPT
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -d 31.170.8.10 -j ACCEPT
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -d 31.170.8.217 -j ACCEPT
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -d 31.170.8.218 -j ACCEPT
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -d 127.0.0.1 -j ACCEPT
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -j LOG --log-uid
|
|
||||||
/sbin/iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-port 8888
|
|
||||||
|
|
||||||
#43251
|
|
||||||
iptables -I INPUT -s 5.188.211.0/24 -p tcp --dport 80 -j DROP
|
|
||||||
iptables -I INPUT -s 5.188.211.0/24 -p tcp --dport 443 -j DROP
|
|
||||||
|
|
||||||
/sbin/iptables -A INPUT -p tcp --sport 2222 --dport 1024:65535 -s 31.170.11.167,31.170.8.7,31.170.8.249,31.170.8.76,31.170.8.222 -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
|
|
||||||
# Ticket #52247 : Blocage git / Autorisation port 22 en IPv6
|
|
||||||
/sbin/ip6tables -A INPUT -p tcp ! --syn --sport 22 -s ::/0 -j ACCEPT
|
|
|
@ -1,492 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# minifirewall is shellscripts for easy firewalling on a standalone server
|
|
||||||
# we used netfilter/iptables http://netfilter.org/ designed for recent Linux kernel
|
|
||||||
# See https://gitea.evolix.org/evolix/minifirewall
|
|
||||||
|
|
||||||
# Copyright (c) 2007-2020 Evolix
|
|
||||||
# This program is free software; you can redistribute it and/or
|
|
||||||
# modify it under the terms of the GNU General Public License
|
|
||||||
# as published by the Free Software Foundation; either version 3
|
|
||||||
# of the License.
|
|
||||||
|
|
||||||
# Description
|
|
||||||
# script for standalone server
|
|
||||||
|
|
||||||
# Start or stop minifirewall
|
|
||||||
#
|
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: minfirewall
|
|
||||||
# Required-Start:
|
|
||||||
# Required-Stop:
|
|
||||||
# Should-Start: $network $syslog $named
|
|
||||||
# Should-Stop: $syslog
|
|
||||||
# Default-Start: 2 3 4 5
|
|
||||||
# Default-Stop: 0 1 6
|
|
||||||
# Short-Description: start and stop the firewall
|
|
||||||
# Description: Firewall designed for standalone server
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
DESC="minifirewall"
|
|
||||||
NAME="minifirewall"
|
|
||||||
|
|
||||||
|
|
||||||
# Variables configuration
|
|
||||||
#########################
|
|
||||||
|
|
||||||
# iptables paths
|
|
||||||
IPT=/sbin/iptables
|
|
||||||
IPT6=/sbin/ip6tables
|
|
||||||
|
|
||||||
# TCP/IP variables
|
|
||||||
LOOPBACK='127.0.0.0/8'
|
|
||||||
CLASSA='10.0.0.0/8'
|
|
||||||
CLASSB='172.16.0.0/12'
|
|
||||||
CLASSC='192.168.0.0/16'
|
|
||||||
CLASSD='224.0.0.0/4'
|
|
||||||
CLASSE='240.0.0.0/5'
|
|
||||||
ALL='0.0.0.0'
|
|
||||||
BROAD='255.255.255.255'
|
|
||||||
PORTSROOT='0:1023'
|
|
||||||
PORTSUSER='1024:65535'
|
|
||||||
|
|
||||||
chain_exists()
|
|
||||||
{
|
|
||||||
local chain_name="$1" ; shift
|
|
||||||
[ $# -eq 1 ] && local intable="--table $1"
|
|
||||||
iptables $intable -nL "$chain_name" >/dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Configuration
|
|
||||||
oldconfigfile="/etc/firewall.rc"
|
|
||||||
configfile="/etc/default/minifirewall"
|
|
||||||
|
|
||||||
IPV6=$(grep "IPV6=" /etc/default/minifirewall | awk -F '=' -F "'" '{print $2}')
|
|
||||||
DOCKER=$(grep "DOCKER=" /etc/default/minifirewall | awk -F '=' -F "'" '{print $2}')
|
|
||||||
INT=$(grep "INT=" /etc/default/minifirewall | awk -F '=' -F "'" '{print $2}')
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
|
|
||||||
echo "Start IPTables rules..."
|
|
||||||
|
|
||||||
# Stop and warn if error!
|
|
||||||
set -e
|
|
||||||
trap 'echo "ERROR in minifirewall configuration (fix it now!) or script manipulation (fix yourself)." ' INT TERM EXIT
|
|
||||||
|
|
||||||
|
|
||||||
# sysctl network security settings
|
|
||||||
##################################
|
|
||||||
|
|
||||||
# Don't answer to broadcast pings
|
|
||||||
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
|
|
||||||
|
|
||||||
# Ignore bogus ICMP responses
|
|
||||||
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
|
|
||||||
|
|
||||||
# Disable Source Routing
|
|
||||||
for i in /proc/sys/net/ipv4/conf/*/accept_source_route; do
|
|
||||||
echo 0 > $i
|
|
||||||
done
|
|
||||||
|
|
||||||
# Enable TCP SYN cookies to avoid TCP-SYN-FLOOD attacks
|
|
||||||
# cf http://cr.yp.to/syncookies.html
|
|
||||||
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
|
|
||||||
|
|
||||||
# Disable ICMP redirects
|
|
||||||
for i in /proc/sys/net/ipv4/conf/*/accept_redirects; do
|
|
||||||
echo 0 > $i
|
|
||||||
done
|
|
||||||
|
|
||||||
for i in /proc/sys/net/ipv4/conf/*/send_redirects; do
|
|
||||||
echo 0 > $i
|
|
||||||
done
|
|
||||||
|
|
||||||
# Enable Reverse Path filtering : verify if responses use same network interface
|
|
||||||
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
|
|
||||||
echo 1 > $i
|
|
||||||
done
|
|
||||||
|
|
||||||
# log des paquets avec adresse incoherente
|
|
||||||
for i in /proc/sys/net/ipv4/conf/*/log_martians; do
|
|
||||||
echo 1 > $i
|
|
||||||
done
|
|
||||||
|
|
||||||
# IPTables configuration
|
|
||||||
########################
|
|
||||||
|
|
||||||
$IPT -N LOG_DROP
|
|
||||||
$IPT -A LOG_DROP -j LOG --log-prefix '[IPTABLES DROP] : '
|
|
||||||
$IPT -A LOG_DROP -j DROP
|
|
||||||
$IPT -N LOG_ACCEPT
|
|
||||||
$IPT -A LOG_ACCEPT -j LOG --log-prefix '[IPTABLES ACCEPT] : '
|
|
||||||
$IPT -A LOG_ACCEPT -j ACCEPT
|
|
||||||
|
|
||||||
if test -f $oldconfigfile; then
|
|
||||||
echo "$oldconfigfile is deprecated, rename to $configfile" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! test -f $configfile; then
|
|
||||||
echo "$configfile does not exist" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmpfile=`mktemp`
|
|
||||||
. $configfile 2>$tmpfile >&2
|
|
||||||
if [ -s $tmpfile ]; then
|
|
||||||
echo "$configfile returns standard or error output (see below). Stopping." >&2
|
|
||||||
cat $tmpfile
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
rm $tmpfile
|
|
||||||
|
|
||||||
# Trusted ip addresses
|
|
||||||
$IPT -N ONLYTRUSTED
|
|
||||||
$IPT -A ONLYTRUSTED -j LOG_DROP
|
|
||||||
for x in $TRUSTEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I ONLYTRUSTED -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# Privilegied ip addresses
|
|
||||||
# (trusted ip addresses *are* privilegied)
|
|
||||||
$IPT -N ONLYPRIVILEGIED
|
|
||||||
$IPT -A ONLYPRIVILEGIED -j ONLYTRUSTED
|
|
||||||
for x in $PRIVILEGIEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I ONLYPRIVILEGIED -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# Chain for restrictions (blacklist IPs/ranges)
|
|
||||||
$IPT -N NEEDRESTRICT
|
|
||||||
|
|
||||||
# We allow all on loopback interface
|
|
||||||
$IPT -A INPUT -i lo -j ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -i lo -j ACCEPT
|
|
||||||
# if OUTPUTDROP
|
|
||||||
$IPT -A OUTPUT -o lo -j ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -o lo -j ACCEPT
|
|
||||||
|
|
||||||
# We avoid "martians" packets, typical when W32/Blaster virus
|
|
||||||
# attacked windowsupdate.com and DNS was changed to 127.0.0.1
|
|
||||||
# $IPT -t NAT -I PREROUTING -s $LOOPBACK -i ! lo -j DROP
|
|
||||||
$IPT -A INPUT -s $LOOPBACK ! -i lo -j DROP
|
|
||||||
|
|
||||||
|
|
||||||
if [ "$DOCKER" = "on" ]; then
|
|
||||||
|
|
||||||
$IPT -N MINIFW-DOCKER-TRUSTED
|
|
||||||
$IPT -A MINIFW-DOCKER-TRUSTED -j DROP
|
|
||||||
|
|
||||||
$IPT -N MINIFW-DOCKER-PRIVILEGED
|
|
||||||
$IPT -A MINIFW-DOCKER-PRIVILEGED -j MINIFW-DOCKER-TRUSTED
|
|
||||||
$IPT -A MINIFW-DOCKER-PRIVILEGED -j RETURN
|
|
||||||
|
|
||||||
$IPT -N MINIFW-DOCKER-PUB
|
|
||||||
$IPT -A MINIFW-DOCKER-PUB -j MINIFW-DOCKER-PRIVILEGED
|
|
||||||
$IPT -A MINIFW-DOCKER-PUB -j RETURN
|
|
||||||
|
|
||||||
# Flush DOCKER-USER if exist, create it if absent
|
|
||||||
if chain_exists 'DOCKER-USER'; then
|
|
||||||
$IPT -F DOCKER-USER
|
|
||||||
else
|
|
||||||
$IPT -N DOCKER-USER
|
|
||||||
fi;
|
|
||||||
|
|
||||||
# Pipe new connection through MINIFW-DOCKER-PUB
|
|
||||||
$IPT -A DOCKER-USER -i $INT -m state --state NEW -j MINIFW-DOCKER-PUB
|
|
||||||
$IPT -A DOCKER-USER -j RETURN
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Local services restrictions
|
|
||||||
#############################
|
|
||||||
|
|
||||||
# Allow services for $INTLAN (local server or local network)
|
|
||||||
$IPT -A INPUT -s $INTLAN -j ACCEPT
|
|
||||||
|
|
||||||
# Enable protection chain for sensible services
|
|
||||||
for x in $SERVICESTCP1p
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp --dport $x -j NEEDRESTRICT
|
|
||||||
done
|
|
||||||
|
|
||||||
for x in $SERVICESUDP1p
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p udp --dport $x -j NEEDRESTRICT
|
|
||||||
done
|
|
||||||
|
|
||||||
# Public service
|
|
||||||
for x in $SERVICESTCP1
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp --dport $x -j ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -p tcp --dport $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
for x in $SERVICESUDP1
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p udp --dport $x -j ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -p udp --dport $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# Privilegied services
|
|
||||||
for x in $SERVICESTCP2
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp --dport $x -j ONLYPRIVILEGIED
|
|
||||||
done
|
|
||||||
|
|
||||||
for x in $SERVICESUDP2
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p udp --dport $x -j ONLYPRIVILEGIED
|
|
||||||
done
|
|
||||||
|
|
||||||
# Private services
|
|
||||||
for x in $SERVICESTCP3
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp --dport $x -j ONLYTRUSTED
|
|
||||||
done
|
|
||||||
|
|
||||||
for x in $SERVICESUDP3
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p udp --dport $x -j ONLYTRUSTED
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
if [ "$DOCKER" = "on" ]; then
|
|
||||||
|
|
||||||
# Public services defined in SERVICESTCP1 & SERVICESUDP1
|
|
||||||
for dstport in $SERVICESTCP1
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-PUB -p tcp --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
|
|
||||||
for dstport in $SERVICESUDP1
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-PUB -p udp --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
|
|
||||||
# Privileged services (accessible from privileged & trusted IPs)
|
|
||||||
for dstport in $SERVICESTCP2
|
|
||||||
do
|
|
||||||
for srcip in $PRIVILEGIEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-PRIVILEGED -p tcp -s "$srcip" --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
|
|
||||||
for srcip in $TRUSTEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-PRIVILEGED -p tcp -s "$srcip" --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
for dstport in $SERVICESUDP2
|
|
||||||
do
|
|
||||||
for srcip in $PRIVILEGIEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-PRIVILEGED -p udp -s "$srcip" --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
|
|
||||||
for srcip in $TRUSTEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-PRIVILEGED -p udp -s "$srcip" --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
# Trusted services (accessible from trusted IPs)
|
|
||||||
for dstport in $SERVICESTCP3
|
|
||||||
do
|
|
||||||
for srcip in $TRUSTEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-TRUSTED -p tcp -s "$srcip" --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
for dstport in $SERVICESUDP3
|
|
||||||
do
|
|
||||||
for srcip in $TRUSTEDIPS
|
|
||||||
do
|
|
||||||
$IPT -I MINIFW-DOCKER-TRUSTED -p udp -s "$srcip" --dport "$dstport" -j RETURN
|
|
||||||
done
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# External services
|
|
||||||
###################
|
|
||||||
|
|
||||||
# DNS authorizations
|
|
||||||
for x in $DNSSERVEURS
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 53 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
$IPT -A INPUT -p udp --sport 53 --dport $PORTSUSER -s $x -m state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
$IPT -A OUTPUT -o $INT -p udp -d $x --dport 53 --match state --state NEW -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# HTTP (TCP/80) authorizations
|
|
||||||
for x in $HTTPSITES
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 80 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# HTTPS (TCP/443) authorizations
|
|
||||||
for x in $HTTPSSITES
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 443 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# FTP (so complex protocol...) authorizations
|
|
||||||
for x in $FTPSITES
|
|
||||||
do
|
|
||||||
# requests on Control connection
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 21 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
# FTP port-mode on Data Connection
|
|
||||||
$IPT -A INPUT -p tcp --sport 20 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
# FTP passive-mode on Data Connection
|
|
||||||
# WARNING, this allow all connections on TCP ports > 1024
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport $PORTSUSER --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# SSH authorizations
|
|
||||||
for x in $SSHOK
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 22 -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# SMTP authorizations
|
|
||||||
for x in $SMTPOK
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 25 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# secure SMTP (TCP/465 et TCP/587) authorizations
|
|
||||||
for x in $SMTPSECUREOK
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 465 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
$IPT -A INPUT -p tcp ! --syn --sport 587 --dport $PORTSUSER -s $x -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# NTP authorizations
|
|
||||||
for x in $NTPOK
|
|
||||||
do
|
|
||||||
$IPT -A INPUT -p udp --sport 123 -s $x -j ACCEPT
|
|
||||||
$IPT -A OUTPUT -o $INT -p udp -d $x --dport 123 --match state --state NEW -j ACCEPT
|
|
||||||
done
|
|
||||||
|
|
||||||
# Always allow ICMP
|
|
||||||
$IPT -A INPUT -p icmp -j ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A INPUT -p icmpv6 -j ACCEPT
|
|
||||||
|
|
||||||
|
|
||||||
# IPTables policy
|
|
||||||
#################
|
|
||||||
|
|
||||||
# by default DROP INPUT packets
|
|
||||||
$IPT -P INPUT DROP
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -P INPUT DROP
|
|
||||||
|
|
||||||
# by default, no FORWARING (deprecated for Virtual Machines)
|
|
||||||
#echo 0 > /proc/sys/net/ipv4/ip_forward
|
|
||||||
#$IPT -P FORWARD DROP
|
|
||||||
#$IPT6 -P FORWARD DROP
|
|
||||||
|
|
||||||
# by default allow OUTPUT packets... but drop UDP packets (see OUTPUTDROP to drop OUTPUT packets)
|
|
||||||
$IPT -P OUTPUT ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -P OUTPUT ACCEPT
|
|
||||||
$IPT -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
|
||||||
$IPT -A OUTPUT -p udp --match state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
$IPT -A OUTPUT -p udp -j DROP
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -o $INT -p udp --dport 33434:33523 --match state --state NEW -j ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -p udp --match state --state ESTABLISHED,RELATED -j ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -A OUTPUT -p udp -j DROP
|
|
||||||
|
|
||||||
trap - INT TERM EXIT
|
|
||||||
|
|
||||||
echo "...starting IPTables rules is now finish : OK"
|
|
||||||
;;
|
|
||||||
|
|
||||||
stop)
|
|
||||||
|
|
||||||
echo "Flush all rules and accept everything..."
|
|
||||||
|
|
||||||
# Delete all rules
|
|
||||||
$IPT -F INPUT
|
|
||||||
$IPT -F OUTPUT
|
|
||||||
$IPT -F LOG_DROP
|
|
||||||
$IPT -F LOG_ACCEPT
|
|
||||||
$IPT -F ONLYTRUSTED
|
|
||||||
$IPT -F ONLYPRIVILEGIED
|
|
||||||
$IPT -F NEEDRESTRICT
|
|
||||||
[ "$DOCKER" = "off" ] && $IPT -t nat -F
|
|
||||||
$IPT -t mangle -F
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -F INPUT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -F OUTPUT
|
|
||||||
|
|
||||||
if [ "$DOCKER" = "on" ]; then
|
|
||||||
$IPT -F DOCKER-USER
|
|
||||||
$IPT -A DOCKER-USER -j RETURN
|
|
||||||
|
|
||||||
$IPT -F MINIFW-DOCKER-PUB
|
|
||||||
$IPT -X MINIFW-DOCKER-PUB
|
|
||||||
$IPT -F MINIFW-DOCKER-PRIVILEGED
|
|
||||||
$IPT -X MINIFW-DOCKER-PRIVILEGED
|
|
||||||
$IPT -F MINIFW-DOCKER-TRUSTED
|
|
||||||
$IPT -X MINIFW-DOCKER-TRUSTED
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Accept all
|
|
||||||
$IPT -P INPUT ACCEPT
|
|
||||||
$IPT -P OUTPUT ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -P INPUT ACCEPT
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -P OUTPUT ACCEPT
|
|
||||||
#$IPT -P FORWARD ACCEPT
|
|
||||||
#$IPT -t nat -P PREROUTING ACCEPT
|
|
||||||
#$IPT -t nat -P POSTROUTING ACCEPT
|
|
||||||
|
|
||||||
# Delete non-standard chains
|
|
||||||
$IPT -X LOG_DROP
|
|
||||||
$IPT -X LOG_ACCEPT
|
|
||||||
$IPT -X ONLYPRIVILEGIED
|
|
||||||
$IPT -X ONLYTRUSTED
|
|
||||||
$IPT -X NEEDRESTRICT
|
|
||||||
|
|
||||||
echo "...flushing IPTables rules is now finish : OK"
|
|
||||||
;;
|
|
||||||
|
|
||||||
status)
|
|
||||||
|
|
||||||
$IPT -L -n -v --line-numbers
|
|
||||||
$IPT -t nat -L -n -v --line-numbers
|
|
||||||
$IPT -t mangle -L -n -v --line-numbers
|
|
||||||
$IPT6 -L -n -v --line-numbers
|
|
||||||
$IPT6 -t mangle -L -n -v --line-numbers
|
|
||||||
;;
|
|
||||||
|
|
||||||
reset)
|
|
||||||
|
|
||||||
echo "Reset all IPTables counters..."
|
|
||||||
|
|
||||||
$IPT -Z
|
|
||||||
$IPT -t nat -Z
|
|
||||||
$IPT -t mangle -Z
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -Z
|
|
||||||
[ "$IPV6" != "off" ] && $IPT6 -t mangle -Z
|
|
||||||
|
|
||||||
echo "...reseting IPTables counters is now finish : OK"
|
|
||||||
;;
|
|
||||||
|
|
||||||
restart)
|
|
||||||
|
|
||||||
$0 stop
|
|
||||||
$0 start
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
|
|
||||||
echo "Usage: $0 {start|stop|restart|status|reset|squid}"
|
|
||||||
exit 1
|
|
||||||
esac
|
|
||||||
|
|
||||||
exit 0
|
|
Loading…
Reference in a new issue