Table des matières
- 2026:
- 2025:
2 billet(s) pour avril 2026
| Notes go lang programmation fonctionnelle | 2026/04/13 22:27 | Jean-Baptiste |
| Notes ping ICMP | 2026/04/03 23:01 | Jean-Baptiste |
Compilation Noyau patch Grsecurity PAX Linux sous Debian
Compile Noyau Linux, patch avec Grsecurity sous Debian
Vérif user_xattr ?
apt-get update apt-get install kernel-package
$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.9.1-19' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --with-arch-32=i586 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.9.1 (Debian 4.9.1-19)
apt-get install gcc-4.9-plugin-dev apt-get install attr
Téléchargement du patch grsecurity
wget https://grsecurity.net/stable/grsecurity-3.0-3.2.64-201411062032.patch wget https://grsecurity.net/stable/grsecurity-3.0-3.2.64-201411062032.patch.sig gpg --verify grsecurity-3.0-3.2.64-201411062032.patch.sig grsecurity-3.0-3.2.64-201411062032.patch
Téléchargement des sources du noyau Linux
wget https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.64.tar.xz wget https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.64.tar.sign 7z x linux-3.2.64.tar.xz gpg --verify linux-3.2.64.tar.sign linux-3.2.64.tar
On va “patcher” : On test avant
patch --dry-run -p1 < ../grsecurity-3.0-3.2.64-201411062032.patch
Allons-y
patch -p1 < ../grsecurity-3.0-3.2.64-201411062032.patch
C'est fait. Compilons…. Re
ls -lrt /boot/config-3.* cp /boot/config-3.16-3-amd64 .config make oldconfig make menuconfig
ou
make defconfig
Si vous avez un quadcore pas chargé
$ #getconf _NPROCESSORS_ONLN $ nproc 4
export CONCURRENCY_LEVEL=4
C'est l’équivalent du make -j 4 ou de export MAKEFLAGS=“-j4”. Mais pour make-kpkg, la variable MAKEFLAGS ne doit pas être définie. unset MAKEFLAGS si besion.
Ou plus simple
export CONCURRENCY_LEVEL=$(nproc)
Pour compiler le noyau Linux sous Debian
Ca y ai, on compile
fakeroot make-kpkg --initrd --append-to-version="gnugrs" kernel-image kernel-headers
On va avoir besoin de changer des droits PAX (inclus avec Grsecurity) Install du pachet attr qui inclue l'outil setfattr (on va en avoir besoin, sinon certain programe de marcherons plus que nous démarrrons avec le nouveau noyeau)
apt-get install attr
- # Ancienne méthode
Téléchargement du script fourni avec le projet Mempo
wget https://raw.githubusercontent.com/mempo/deterministic-kernel/master/apps/grsec-setpax/postinstall/fs_attr_grsecurity_standard_debian.sh chmod +x fs_attr_grsecurity_standard_debian.sh sudo ./fs_attr_grsecurity_standard_debian.sh
Personnellement, c'est été oublié à rajouté :
setfattr -n user.pax.flags -v "rm" /usr/lib/icedove/icedove setfattr -n user.pax.flags -v "rm" /usr/lib/iceweasel/iceweasel setfattr -n user.pax.flags -v "m" /usr/lib/iceweasel/plugin-container setfattr -n user.pax.flags -v "E" /usr/bin/python3.4 setfattr -n user.pax.flags -v "m" /usr/bin/nodejs setfattr -n user.pax.flags -v "m" /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Ou avec paxctl
Configuration PAX paxctld.conf
/etc/paxctld.conf
/usr/lib/icedove/icedove rm
/usr/lib/iceweasel/iceweasel rm
/usr/lib/iceweasel/plugin-container m
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java m
Nouvelle méthode
gpg --verify paxctld_1.0-2_amd64.deb.sig paxctld_1.0-2_amd64.deb
gpg: Signature faite le jeu. 01 janv. 2015 18:09:39 CET gpg: avec la clef RSA 0x44D1C0F82525FE49 gpg: Bonne signature de « Bradley Spengler (spender) <spender@grsecurity.net> » [inconnu] gpg: Attention : cette clef n'est pas certifiée avec une signature de confiance. gpg: Rien n'indique que la signature appartient à son propriétaire. Empreinte de clef principale : DE94 52CE 46F4 2094 907F 108B 44D1 C0F8 2525 FE49
dpkg -i paxctld_1.0-2_amd64.deb
Plus rien à faire. La conf se trouve dans */etc/paxctld.conf* et le daemon paxctld s'occupe de tout. Dans mon cas, la conf par défaut suffit.
Il est important de vérifier (et de superviser) que le service paxctld soit bien démarré, et activé pour démarrer automatiquement.
En cas de mise à jour faut-il systématiquement redémarrer le service paxctld !?
sysctl
Pour voir les propriétés modifiable à chaud
sysctl -a | egrep "kernel.pax.|kernel.grsecurity."
Exemple de fichier de conf (ordi de bureau)
/etc/sysctl.d/05-grsecurity.conf
kernel.grsecurity.linking_restrictions = 1 kernel.grsecurity.enforce_symlinksifowner = 1 kernel.grsecurity.deter_bruteforce = 1 kernel.grsecurity.fifo_restrictions = 1 kernel.grsecurity.ptrace_readexec = 1 kernel.grsecurity.consistent_setxid = 1 kernel.grsecurity.ip_blackhole = 1 kernel.grsecurity.lastack_retries = 4 kernel.grsecurity.chroot_deny_shmat = 1 kernel.grsecurity.chroot_deny_unix = 1 kernel.grsecurity.chroot_deny_mount = 1 kernel.grsecurity.chroot_deny_fchdir = 1 kernel.grsecurity.chroot_deny_chroot = 1 kernel.grsecurity.chroot_deny_pivot = 1 kernel.grsecurity.chroot_enforce_chdir = 1 kernel.grsecurity.chroot_deny_chmod = 1 kernel.grsecurity.chroot_deny_mknod = 1 kernel.grsecurity.chroot_restrict_nice = 1 kernel.grsecurity.chroot_caps = 1 kernel.grsecurity.chroot_deny_sysctl = 1 kernel.grsecurity.chroot_findtask = 1 # TPE : Trusted Path Execution. kernel.grsecurity.tpe = 1 # Drastique. Plus d exec dans le home kernel.grsecurity.tpe_restrict_all = 1 #kernel.grsecurity.socket_all = 1 #kernel.grsecurity.socket_client = 1 #kernel.grsecurity.socket_server = 1 kernel.grsecurity.harden_ptrace = 1 # For mplayer2 with x11 drivers (full screen) # else "vo=x11,sdl" => "vo=xv,directfb" in /etc/mplayer2/mplayer.conf kernel.grsecurity.harden_ipc = 0 # Drastique. Rebbot necessaire pour revenir en arriere # Empeche ecryptfs de fonctionner #kernel.grsecurity.romount_protect = 1 ## Desactiv kernel.grsecurity.dmesg = 0 kernel.grsecurity.deny_new_usb = 0 ## Groupes #kernel.grsecurity.socket_all_gid = 1004 #kernel.grsecurity.socket_client_gid = 1003 #kernel.grsecurity.socket_server_gid = 1002 #kernel.grsecurity.audit_gid = 1007 kernel.grsecurity.tpe_gid = 1005 #kernel.grsecurity.symlinkown_gid = 1006 ## Audit #kernel.grsecurity.audit_group = 1 # Si activé vraiment bavard kernel.grsecurity.audit_chdir = 0 kernel.grsecurity.audit_mount = 1 kernel.grsecurity.audit_ptrace = 1 ## Logging #kernel.grsecurity.exec_logging = 1 #kernel.grsecurity.rwxmap_logging = 1 kernel.grsecurity.signal_logging = 1 kernel.grsecurity.forkfail_logging = 1 kernel.grsecurity.timechange_logging = 1 #kernel.grsecurity.chroot_execlog = 1 #kernel.grsecurity.resource_logging = 1 # Test kernel.grsecurity.disable_priv_io = 1 ## Dernier parametre # Drastique. Interdit toutes modifications de ces parametres. Reboot necessaire pour rechanger #kernel.grsecurity.grsec_lock = 1
Cette conf sera appliquée au démarrage du PC ou bien :
sysctl -p /etc/sysctl.d/05-grsecurity.conf
Exemple de changement de conf à chaud La pluspart des problèmes sont résolut en abaissant la sécurité de la façon suivantes :
sysctl -w kernel.pax.softmode=1 sysctl -w kernel.grsecurity.tpe=0
Plus de son ? Pour un ordi de bureau : CONFIG_GRKERNSEC_SYSFS_RESTRICT=n
http://arunraghavan.net/2012/10/grsec-and-pulseaudio/
Liens :
http://www.chromium.org/chromium-os/chromiumos-design-docs/system-hardening
http://en.wikibooks.org/wiki/Grsecurity/The_RBAC_System
http://linux.developpez.com/cours/securedeb/?page=annexe12
http://www.cs.virginia.edu/~jcg8f/GrsecuritySELinuxCaseStudy.pdf
http://www.cs.virginia.edu/~jcg8f/SELinux%20grsecurity%20paper.pdf
http://judepereira.com/blog/playing-with-grsecurity-a-brief-tutorial/
http://resources.infosecinstitute.com/gentoo-hardening-part-2-introduction-pax-grsecurity/
http://wiki.gentoo.org/wiki/Hardened/PaX_Quickstart
http://wiki.gentoo.org/wiki/Hardened/Grsecurity2_Quickstart
https://grsecurity.net/gracldoc.htm
Pb
Pb Apache prefork fork bruteforce
Voir : https://serverfault.com/questions/460429/clone2-30-sec-delay-in-apache
Symptôme : 30 seconde pour avoir la réponse HTTP d'un fichier statique :
time curl http://localhost/robots.txt
Logs dmesg ou /var/log/kern.log
# dmesg bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for /usr/sbin/apache2[/usr/sbin/apach:49719] uid/euid:33/33 gid/egid:33/33, parent /usr/sbin/apache2[/usr/sbin/apach:52102] uid/euid:0/0 gid/egid:0/0
/var/log/apache2/error.log
[Thu Jan 17 11:31:03.452626 2019] [mpm_itk:error] [pid 53254] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 12:07:55.121999 2019] [mpm_prefork:error] [pid 27073] (12)Cannot allocate memory: AH00159: fork: Unable to fork new process [Thu Jan 17 12:07:55.516731 2019] [mpm_itk:error] [pid 60456] child died with signal 11 [Thu Jan 17 13:57:28.126583 2019] [mpm_itk:error] [pid 13856] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 14:30:49.613734 2019] [mpm_itk:error] [pid 18798] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 14:30:49.628835 2019] [mpm_itk:error] [pid 20078] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 14:30:49.735962 2019] [mpm_itk:error] [pid 20018] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 14:30:49.748244 2019] [mpm_itk:error] [pid 18798] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 14:30:49.852928 2019] [mpm_itk:error] [pid 20073] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 14:30:49.865209 2019] [mpm_itk:error] [pid 20018] (12)Cannot allocate memory: fork: Unable to fork new process [Thu Jan 17 14:30:50.006418 2019] [mpm_itk:error] [pid 20078] (12)Cannot allocate memory: fork: Unable to fork new process [crit] Memory allocation failed, aborting process.
Apache forkant souvent et rapidement grsec prend cela pour une tentative de bruteforce
Cela est dû à GRSecurity, à plus précisément à l'option suivante de compilation du Kernel :
CONFIG_GRKERNSEC_BRUTE=y
Solution possible :
- Passer Apache en mode worker ou lieu de prefork
- Désactiver grsec
- Modifier la conf Apache pour qu'il fork moins
- Maintenance palliative : chien de garde (A tester)
/etc/apache2/mods-available/mpm_prefork.conf
<IfModule mpm_prefork_module> #StartServers 5 StartServers 140 #MinSpareServers 5 MinSpareServers 20 #MaxSpareServers 10 MaxSpareServers 30 MaxClients 150 MaxRequestsPerChild 0 </IfModule>
Tentative de chien de garde via crontab chaque minute
/usr/local/bin/fix_apache_grkernsecbrut.sh
#! /bin/bash curl --resolve www.acme.fr:443:127.0.0.1 --max-time 10 --connect-timeout 10 http://www.acme.fr/robots.txt >/dev/null 2>&1 if [[ $? == 28 ]] then date >> /root/${0}.log /usr/sbin/apachectl graceful & fi
Compilation OpenCV sur Debian
Voir aussi :
- skimage est une alternative à OpenCV
- YOLO (Python)
Compilation et installation d'OpenCV 3.3.0 sous Debian 9
Prérequis
sudo apt-get update sudo apt-get install -y build-essential sudo apt-get install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev sudo apt-get -y install unzip # Pour la création du .deb sudo apt-get install -y fakeroot checkinstall
Téléchargement des sources
mkdir ~/src cd ~/src wget https://github.com/opencv/opencv/archive/3.3.0.zip unzip 3.3.0.zip
Pas nécessaire si -DWITH_IPP=OFF on option de compilation
mkdir -p ~/src/opencv-3.3.0/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b/ cd !$ export https_proxy=http://192.168.56.1:3128 wget https://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv/ippicv_linux_20141027.tgz
Compilation
cd ~/src/opencv-3.3.0/cmake #cmake -DWITH_CUDA=OFF -DWITH_QT=OFF -DWITH_OPENGL=OFF -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF .. #cmake -DCMAKE_INSTALL_PREFIX=/usr/lib/opencv3.0 -DWITH_FFMPEG=OFF -DWITH_IPP=OFF -DWITH_CUDA=OFF -DWITH_QT=OFF -DWITH_OPENGL=OFF -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF .. cmake -DBUILD_TIFF=ON \ -DBUILD_opencv_java=OFF \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_EXAMPLES=OFF \ -DBUILD_TESTS=OFF \ -DBUILD_PERF_TESTS=OFF \ -DWITH_CUDA=ON \ -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \ -DCUDA_ARCH_BIN='3.0 3.5 5.0 6.0 6.2' \ -DCUDA_ARCH_PTX="" \ -DCPU_DISPATCH=AVX,AVX2 \ -DENABLE_PRECOMPILED_HEADERS=OFF \ -DWITH_OPENGL=OFF \ -DWITH_OPENCL=OFF \ -DWITH_QT=OFF \ -DWITH_IPP=ON \ -DWITH_TBB=ON \ -DFORCE_VTK=ON \ -DWITH_EIGEN=ON \ -DWITH_V4L=ON \ -DWITH_XINE=ON \ -DWITH_GDAL=ON \ -DWITH_1394=OFF \ -DWITH_FFMPEG=OFF \ -DBUILD_PROTOBUF=OFF \ -DCMAKE_BUILD_TYPE=RELEASE \ -DCMAKE_INSTALL_PREFIX=/usr/lib/opencv3.3 \ .. make -j $(nproc)
Installation
sudo make install
Création d'un paquet Debian avec checkinstall
cat >description-pak <<EOF libopencv This package contains the header files and static library needed to compile applications that use OpenCV (Open Computer Vision) core. . The Open Computer Vision Library is a collection of algorithms and sample code for various computer vision problems. The library is compatible with IPL (Intel's Image Processing Library) and, if available, can use IPP (Intel's Integrated Performance Primitives) for better performance. . OpenCV provides low level portable data types and operators, and a set of high level functionalities for video acquisition, image processing and analysis, structural analysis, motion analysis and object tracking, object recognition, camera calibration and 3D reconstruction. EOF echo |fakeroot checkinstall --install=no \ --strip \ --stripso \ --addso \ --exclude '/home' \ --gzman \ --reset-uids \ --maintainer 'ACME SAS \<[mailto:root@acme.fr\>]root@acme.fr\>' \ --pkglicense 'Copyright' \ --pkgname opencv-all3.3 \ --pkgrelease 1 \ --pkgversion 3.3.0 \ --pkgsource 'https://github.com/opencv/opencv/archive/3.3.0.zip'
TODO : ldconfig
Exemple
- DEBIAN/shlibs
libcudnn 7 libcudnn7
Voir http://man7.org/linux/man-pages/man5/deb-shlibs.5.html
- DEBIAN/triggers
# Triggers added by dh_makeshlibs/11.1.6ubuntu2 activate-noawait ldconfig
Voir : https://manpages.debian.org/unstable/dpkg-dev/deb-triggers.5.fr.html
Compilation du module Python PySVN sous RedHat
Compilation
sudo yum groupinstall "Development Tools" sudo yum install python2-devel subversion-devel mkdir ~/compile cd !$ export http_proxy=http://127.0.0.1:3128 export https_proxy=http://127.0.0.1:3128 wget https://downloads.sourceforge.net/project/pysvn/pysvn/V1.9.11/pysvn-1.9.11.tar.gz tar xf pysvn-1.9.11.tar.gz cd ~/compile/pysvn-1.9.11/Import/pycxx-7.1.3 #./build-all.sh ./build-unlimited-api.sh python2.7 #python setup.py install cd ~/compile/pysvn-1.9.11/Source ln -s ~/compile/pysvn-1.9.11/Import/pycxx-7.1.3/Src Src #./build.sh python2 setup.py configure --enable-debug --verbose --pycxx-dir=$HOME/compile/pysvn-1.9.11/Import/pycxx-7.1.3 make -j $(nproc)
Test
env PYTHONPATH=$PWD python2 <<< "import pysvn"
Installation
sudo cp -r ~/compile/pysvn-1.9.11/Source/pysvn /usr/lib64/python2.7/
Commande mail - SMTP client MUA Mail User Agent
Voir aussi :
- ssmtp / msmtp / /usr/sbin/sendmail
- LMTP
- curl smtp / smtps
echo -e "Chers collègues je vous offre les croissants et du chocolat pour mardi de Pâques\n\nCordialement,\nPierre Dupont" |mail -r 'pierre.dupont@acme.fr (Pierre Dupont)' -s "Croissants !" toutelequipe@acme.fr touslescopains@acme.fr pierre.dupont@acme.fr
Voir : https://www.croissantage.fr/
echo "plop" |mail -s "Sujet" contact@acme.fr -aFrom:root@acme.fr echo "plop" |mutt -e 'my_hdr From:root@acme.fr' -s "Sujet" contact@acme.fr
cat << EOM |sendmail -it -f test@acme.fr From:test@acme.fr To: <contact@plop.com> Subject: Sujet Message EOM
En encore avec curl
curl --mail-from phil@mydmn.org --mail-rcpt bob@mydmn.org smtp://srv-smtp.mydmn.org
Autre
echo Test 1 |mail -v -s "Test 1" testmail@acme.fr Resolving host fed-smtp.acme.fr . . . done. Connecting to 192.168.1.12:smtp . . . connected. 220 smtp1.localdomain ESMTP Postfix >>> HELO srv1.acme.fr 250 smtp1.localdomain >>> MAIL FROM:<root@srv1.acme.fr> 250 2.1.0 Ok >>> RCPT TO:<testmail@acme.fr> 250 2.1.5 Ok >>> DATA 354 End data with <CR><LF>.<CR><LF> >>> . 250 2.0.0 Ok: queued as 4RTx2c31XTz2Q >>> QUIT 221 2.0.0 Bye
/etc/postfix/main.cf
relayhost = fed-smtp.acme.fr
Coloration des pages man grâce à Most
http://identity-labs.fr/article-5-installation-dun-serveur-lamp-debian-zend-server
Nous allons installer Most, un utilitaire qui ajoute la coloration aux pages de manuel:
apt-get install most
Puis indiquons à man qu'il doit utiliser most
update-alternatives --config pager
