Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Blot committed Sep 20, 2017
0 parents commit 868f96c
Show file tree
Hide file tree
Showing 270 changed files with 8,888 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
*.txt
*.orig
*.gdbhistory
*.swp
.deps
.libs
*.lo
src/tests/*.diff
src/tests/*.exp
src/tests/*.log
src/tests/*.out
src/tests/*.sh
src/tests/*.php
# Files generated by phpize, configure and make
src/autom4te.cache
src/build
src/modules
src/acinclude.m4
src/aclocal.m4
src/config.guess
src/config.h
src/config.h.in
src/config.log
src/config.nice
src/config.status
src/config.sub
src/configure
src/configure.in
src/install-sh
src/*.la
src/ltmain.sh
src/libtool
src/Makefile
src/Makefile.fragments
src/Makefile.global
src/Makefile.objects
src/missing
src/mkinstalldirs
src/run-tests.php
165 changes: 165 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.

"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.

An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.

A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".

The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.

The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:

a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or

b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the object code with a copy of the GNU GPL and this license
document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:

a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.

c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.

d) Do one of the following:

0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.

1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.

e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.

b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser 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
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
clean:
make -C src clean
cd src; phpize --clean

debug:
cd src; phpize
export CFLAGS="-Wall -Wextra -g3 -ggdb -Wno-unused-function"; cd src; ./configure --enable-snuffleupagus --enable-debug
make -C src
TEST_PHP_ARGS='-q' REPORT_EXIT_STATUS=1 make -C src test

coverage:
cd src; phpize
export CFLAGS="--coverage -fprofile-arcs -ftest-coverage -O0"; export LDFLAGS="--coverage"; cd src; ./configure --enable-snuffleupagus --enable-coverage
make -C src
lcov --base-directory src --directory ./src --zerocounters -q --rc lcov_branch_coverage=1
rm -Rf src/COV.html
TEST_PHP_ARGS='-q' REPORT_EXIT_STATUS=1 make -C src test
lcov --base-directory ./src --directory src -c -o ./src/COV.info --rc lcov_branch_coverage=1 2>/dev/null 1>/dev/null
lcov --remove src/COV.info '/usr/*' --remove src/COV.info '*tweetnacl.c' -o src/COV.info --rc lcov_branch_coverage=1 2>/dev/null 1>/dev/null
genhtml -o src/COV.html ./src/COV.info --branch-coverage

tests: joomla

joomla:
if [ -nd "joomla-cms" ]; then git clone --depth 1 [email protected]:joomla/joomla-cms.git; fi
cd joomla-cms; composer install
cd joomla-cms; libraries/vendor/phpunit/phpunit/phpunit -d extension=./src/modules/snuffleupagus.so

packages: debian

debian:
dpkg-buildpackage -i -us -uc -tc -I -rfakeroot
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[![build
status](https://gitlab.nbs-system.com/secu/snuffleupagus/badges/master/build.svg)](https://gitlab.nbs-system.com/secu/snuffleupagus/commits/master)
[![coverage
report](https://gitlab.nbs-system.com/secu/snuffleupagus/badges/master/coverage.svg)](https://gitlab.nbs-system.com/secu/snuffleupagus/commits/master)
[Documentation]( https://secu.gitlab-pages.nbs-system.com/snuffleupagus/ )

# Code style
We're using [clang-format](http://clang.llvm.org/docs/ClangFormat.html) to
ensure a consistent code-style. Please run it with `clang-format -style=google`
before committing, or even better, use a [pre-commit hook](https://github.com/andrewseidl/githook-clang-format)

# Resources
- The [writeup]( https://github.com/beberlei/whitewashing.de/blob/master/drafts/porting_extension_to_php7.rst) of [tideway profiler](https://github.com/tideways/php-profiler-extension)'s port to php7
- [Upgrading to php-ng]( https://wiki.php.net/phpng-upgrading )
- PHP7 [virtual machine](https://nikic.github.io/2017/04/14/PHP-7-Virtual-machine.html)
54 changes: 54 additions & 0 deletions config/default.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Harden the `chmod` function
sp.disable_functions.function("chmod").param("mode").value_r("^[0-9]{2}[67]$").drop();
sp.disable_functions.function("chmod").param("mode").value_r("o\\+w$").drop();

# Prevent various `mail`-related vulnerabilities
sp.disable_functions.function("mail").param("additional_parameters").value_r("\\-").drop();

##Prevent various `include`-related vulnerabilities
sp.disable_functions.function_r("^(?:require|include)_once$").value_r("\\.(?:php|php7|inc|tpl)$").allow();
sp.disable_functions.function_r("^require|include$").value_r("\\.(?:php|php7|inc|tpl)$").allow();
sp.disable_functions.function_r("^(?:require|include)_once$").drop();
sp.disable_functions.function_r("^require|include$").drop();

# Prevent `system`-related injections
sp.disable_functions.function("system").param("command").value_r("[$|;&`\\n]").drop();
sp.disable_functions.function("shell_exec").param("command").value_r("[$|;&`\\n]").drop();
sp.disable_functions.function("exec").param("command").value_r("[$|;&`\\n]").drop();
sp.disable_functions.function("proc_open").param("command").value_r("[$|;&`\\n]").drop();

# Prevent runtime modification of interesting things
sp.disable_functions.function("ini_set").param("var_name").value("assert.active").drop();
sp.disable_functions.function("ini_set").param("var_name").value("zend.assertions").drop();
sp.disable_functions.function("ini_set").param("var_name").value("memory_limit").drop();
sp.disable_functions.function("ini_set").param("var_name").value("include_path").drop();
sp.disable_functions.function("ini_set").param("var_name").value("open_basedir").drop();

# Detect some backdoors via environnement recon
sp.disable_functions.function("ini_get").param("var_name").value_r("(?:allow_url_fopen|open_basedir|suhosin)").drop();
sp.disable_functions.function("function_exists").param("function_name").value_r("(?:eval|exec|system)").drop();
sp.disable_functions.function("is_callable").param("var").value_r("(?:eval|exec|system)").drop();

# Ghetto sqli hardening
sp.disable_functions.function_r("mysqli?_query").param("query").value_r("/\\*").drop();
sp.disable_functions.function_r("mysqli?_query").param("query").value_r("--").drop();
sp.disable_functions.function_r("mysqli?_query").param("query").value_r("#").drop();
sp.disable_functions.function_r("mysqli?_query").param("query").value_r(";.*;").drop();
sp.disable_functions.function_r("mysqli?_query").param("query").value_r("benchmark").drop();
sp.disable_functions.function_r("mysqli?_query").param("query").value_r("sleep").drop();
sp.disable_functions.function_r("mysqli?_query").param("query").value_r("information_schema").drop();
sp.disable_functions.function("PDO::query").param("query").value_r("/\\*").drop();
sp.disable_functions.function("PDO::query").param("query").value_r("--").drop();
sp.disable_functions.function("PDO::query").param("query").value_r("#").drop();
sp.disable_functions.function("PDO::query").param("query").value_r(";.*;").drop();
sp.disable_functions.function("PDO::query").param("query").value_r("benchmark\\s*\\(").drop();
sp.disable_functions.function("PDO::query").param("query").value_r("sleep\\s*\\(").drop();
sp.disable_functions.function("PDO::query").param("query").value_r("information_schema").drop();

# Ghetto sqli detection
sp.disable_functions.function_r("mysqli?_query").ret("FALSE").drop();
sp.disable_functions.function_r("PDO::query").ret("FALSE").drop();

#File upload
sp.disable_functions.function("move_uploaded_file").param("destination").value_r("\\.ph").drop();
sp.disable_functions.function("move_uploaded_file").param("destination").value_r("\\.ht").drop();
47 changes: 47 additions & 0 deletions config/examples.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Restrict system calls to specific file
sp.disable_functions.function("system").filename("update.php").allow();
sp.disable_functions.function("system").drop();


# Restrict system calls to specific file with a specific hash
sp.disable_functions.function("system").filename("update.php").hash("d27c6c5686bc129716b6aac8dfefe2d519a80eb6cc144e97ad42c728d423eed0").allow();
sp.disable_functions.function("system").drop();


# AbanteCart 1.2.8 - Multiple SQL Injections <https://blog.ripstech.com/2016/abantecart-multiple-sql-injections>
sp.disable_functions.filename("static_pages/index.php").var("_SERVER[PHP_SELF").value_r("\"").drop().alias("XSS");
sp.disable_functions.filename("core/lib/language_manager.php").function("ALanguageManager>_clone_language_rows").param("from_language").value_r("[^0-9]").drop();
sp.disable_functions.filename("admin/model/tool/backup.php").function("ModelToolBackup>createBackupTask").param("data[table_list]").value_r("'").drop();
# Redaxo 5.2.0: Remote Code Execution via CSRF <https://blog.ripstech.com/2016/redaxo-remote-code-execution-via-csrf>
# See <http://code.vtiger.com/vtiger/vtigercrm/commit/9b5c5338f80237ae072a06e1ba4a5cfcbfe063b0> for details
sp.disable_functions.filename("redaxo/src/addons/structure/pages/linkmap.php").function("substr").param("string").value_r("\"").drop();
# Guest Post: Vtiger 6.5.0 - SQL Injection <https://blog.ripstech.com/2016/vtiger-sql-injection/>
sp.disable_functions.filename("modules/Calendar/Activity.php").function("save_module").param("query").value_r("[^0-9;]").drop();
# The State of Wordpress Security <https://blog.ripstech.com/2016/the-state-of-wordpress-security>
# All In One WP Security & Firewall
sp.disable_functions.filename("admin/wp-security-dashboard-menu.php").function("render_tab3").var("_REQUEST[tab]]").value_r("\"").drop();
# PHPKit 1.6.6: Code Execution for Privileged Users <https://blog.ripstech.com/2016/phpkit-code-exection-for-privileged-users>
sp.disable_functions.filename("pkinc/func/default.php").function("move_uploaded_file").param("destination").value_r("\\.ph\\.+$").drop();
# Coppermine 1.5.42: Second-Order Command Execution <https://blog.ripstech.com/2016/coppermine-second-order-command-execution>
sp.disable_functions.filename("include/imageobject_im.class.php").function("exec").var("CONFIG[im_options]).value_r("[^a-z0-9]").drop();
sp.disable_functions.filename("forgot_passwd.php").function("cpg_db_query").var("CLEAN[id]").value_r("[^a-z0-9]").drop();
# CVE-2014-1610 - Mediawiki RCE
sp.disable_functions.filename("includes/media/DjVu.php")
sp.disable_functions.filename("includes/media/ImageHandler.php").var("_GET[page]").value_r("[^0-9]").drop()
# CVE-2017-1001000 - https://blog.sucuri.net/2017/02/content-injection-vulnerability-wordpress-rest-api.html
sp.disable_functions.filename("wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php").function("register_routes").var("_GET[id]").value_r("[^0-9]").drop();
sp.disable_functions.filename("wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php").function("register_routes").var("_POST[id]").value_r("[^0-9]").drop();
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
snuffleupagus (0.1) UNRELEASED; urgency=medium

* Initial release.

-- jvoisin <[email protected]> Tue, 04 Jul 2017 17:51:31 +0200
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
14 changes: 14 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Source: snuffleupagus
Priority: optional
Maintainer: NBS System <[email protected]>
Build-Depends: debhelper (>= 9), php7.0-dev
Standards-Version: 3.9.2
Homepage: https://snuffleupagus.fr
Section: php
Vcs-Git: https://github.com/nbs-system/snuffleupagus

Package: snuffleupagus
Architecture: any
Depends: ${misc:Depends}
Description: Hardening for your php7 stack
Snuffleupagus is cool
8 changes: 8 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Snuffleupagus
Upstream-Contact: NBS System <[email protected]>
Source: https://github.com/nbs-system/snuffleupagus

Files: *
Copyright: 2017 NBS System
License: LGPL
1 change: 1 addition & 0 deletions debian/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
README.md
Loading

0 comments on commit 868f96c

Please sign in to comment.