Compare commits
3 Commits
47ed93bf21
...
e552583393
Author | SHA1 | Date | |
---|---|---|---|
e552583393 | |||
04eda32fa3 | |||
5e977d44a4 |
@@ -1,6 +1,6 @@
|
|||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:ID: 4fabfe6a-b104-464f-8a87-dfd7d761dbcc
|
:ID: 4fabfe6a-b104-464f-8a87-dfd7d761dbcc
|
||||||
:mtime: 20220207072855
|
:mtime: 20220306173558
|
||||||
:ctime: 20211230101535
|
:ctime: 20211230101535
|
||||||
:END:
|
:END:
|
||||||
#+title: Python
|
#+title: Python
|
||||||
@@ -20,6 +20,9 @@
|
|||||||
*** [[id:6cc56ee4-6d42-4d50-beb3-bb22a98298dd][textual]]
|
*** [[id:6cc56ee4-6d42-4d50-beb3-bb22a98298dd][textual]]
|
||||||
|
|
||||||
* Outils
|
* Outils
|
||||||
|
** Analyseur statique de code
|
||||||
|
*** [[id:1d258869-5421-496a-b296-2d157ebdf3b6][mypy]]
|
||||||
|
*** [[id:113a938e-3fb2-45cb-ae6e-41801418139b][bandit]]
|
||||||
** Formatter
|
** Formatter
|
||||||
*** [[https://github.com/hhatto/autopep8][autopep8]]
|
*** [[https://github.com/hhatto/autopep8][autopep8]]
|
||||||
Utilitaire formattant le code afin de respecter la [[https://www.python.org/dev/peps/pep-0008/][PEP8]] guideline. Il est basé sur l'analyse de code effectuée par
|
Utilitaire formattant le code afin de respecter la [[https://www.python.org/dev/peps/pep-0008/][PEP8]] guideline. Il est basé sur l'analyse de code effectuée par
|
||||||
@@ -31,6 +34,10 @@ En plus de vérifier la conformité avec la [[https://www.python.org/dev/peps/p
|
|||||||
*** [[https://black.readthedocs.io/en/stable/][Black]]
|
*** [[https://black.readthedocs.io/en/stable/][Black]]
|
||||||
Formatter n'appliquant que le style [[https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html][/black/]]. Il accepte la même synthaxe de contrôle que YAPF.
|
Formatter n'appliquant que le style [[https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html][/black/]]. Il accepte la même synthaxe de contrôle que YAPF.
|
||||||
|
|
||||||
|
* Modules intéressants
|
||||||
|
** Vulnérabilités/Cyber
|
||||||
|
*** [[id:ba4c7c25-ee27-4b5e-8ef7-ba2ecc34f127][defusedxml]]
|
||||||
|
|
||||||
* Tips
|
* Tips
|
||||||
** [[id:4ef76164-0e67-410a-8d26-b03071a0cc41][Compter la fréquence des éléments d'une liste]]
|
** [[id:4ef76164-0e67-410a-8d26-b03071a0cc41][Compter la fréquence des éléments d'une liste]]
|
||||||
** [[id:cb3c63b9-6452-4016-9b2f-a25784941d5d][List vs deque]]
|
** [[id:cb3c63b9-6452-4016-9b2f-a25784941d5d][List vs deque]]
|
||||||
|
13
20220306172443-bandit.org
Normal file
13
20220306172443-bandit.org
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: 113a938e-3fb2-45cb-ae6e-41801418139b
|
||||||
|
:mtime: 20220306172631
|
||||||
|
:ctime: 20220306172443
|
||||||
|
:END:
|
||||||
|
#+title: bandit
|
||||||
|
|
||||||
|
* Introduction
|
||||||
|
Bandit est un OSS détectant les failles de sécurité via l'analyse statique de code python.
|
||||||
|
|
||||||
|
* Références
|
||||||
|
* [[https://github.com/PyCQA/bandit][Github]]
|
||||||
|
|
51
20220306172805-defusedxml.org
Normal file
51
20220306172805-defusedxml.org
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: ba4c7c25-ee27-4b5e-8ef7-ba2ecc34f127
|
||||||
|
:mtime: 20220306184630
|
||||||
|
:ctime: 20220306172805
|
||||||
|
:END:
|
||||||
|
#+title: defusedxml
|
||||||
|
|
||||||
|
* Introduction
|
||||||
|
Module proposant une sourcouche protégeant contre les vulnérabilités de certains modules python gérant des données XML.
|
||||||
|
|
||||||
|
Par exemple :
|
||||||
|
#+BEGIN_SRC python
|
||||||
|
from xml.etree.ElementTree import parse
|
||||||
|
et = parse(xmlfile)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Serait à mettre à jour ainsi :
|
||||||
|
#+BEGIN_SRC python
|
||||||
|
from defusedxml.ElementTree import parse
|
||||||
|
et = parse(xmlfile)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
* Liste des vulnérabilités et fonctionnalités
|
||||||
|
|
||||||
|
| Vulnérabilité | sax | etree | minidom | pulldom | xmlrpc | [[id:b18fe210-fac3-4f63-8041-4b686c64ee6a][lxml]] | genshi |
|
||||||
|
|--------------------------------------------+-------+-------+---------+---------+--------+------------+--------|
|
||||||
|
| [[id:7b090d0a-b96b-4d40-afec-2155a6909935][xml billion laughs]] | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ (1) | ✖ (5) |
|
||||||
|
| quadratic blowup | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ (5) |
|
||||||
|
| [[id:869e88ed-fe68-47b5-a911-e27cf3927f66][XML external entity expension]] (remote) | ✔ | ✖ (3) | ✖ (4) | ✔ | ✖ | ✖ (1) | ✖ (5) |
|
||||||
|
| [[id:869e88ed-fe68-47b5-a911-e27cf3927f66][XML external entity expension]] (local file) | ✔ | ✖ (3) | ✖ (4) | ✔ | ✖ | ✔ | ✖ (5) |
|
||||||
|
| DTD retrieval | ✔ | ✖ | ✖ | ✔ | ✖ | ✖ (1) | ✖ |
|
||||||
|
| gzip bomb | ✖ | ✖ | ✖ | ✖ | ✔ | Partly (2) | ✖ |
|
||||||
|
| xpath support (7) | ✖ | ✖ | ✖ | ✖ | ✖ | ✔ | ✖ |
|
||||||
|
| xsl(t) support (7) | ✖ | ✖ | ✖ | ✖ | ✖ | ✔ | ✖ |
|
||||||
|
| xinclude support (7) | ✖ | ✔ (6) | ✖ | ✖ | ✖ | ✔ (6) | ✔ |
|
||||||
|
| C library | expat | expat | expat | expat | expat | libxml2 | expat |
|
||||||
|
|
||||||
|
|
||||||
|
1. /lxml/ est protégé contre les attaques /billion laughs/ et ne fait pas de recherche réseau (/network lookups/) par défaut.
|
||||||
|
2. /libxml2/ et /lxml/ ne sont pas directement vulnérables aux /gzip decompression bombs/ mais ne vous protège pas contre
|
||||||
|
par ailleurs.
|
||||||
|
3. /xml.etree/ ne développe pas les entités et déclenche une /ParserError/ lorsqu'une entité apparait.
|
||||||
|
4. /minicom/ ne développe pas les entités et retourne une entitée textuelle non développée.
|
||||||
|
5. /genshi.input/ (v0.6) ne développe pas les entités et déclenche une /ParserError/ lorsqu'une entité apparait.
|
||||||
|
6. La librarie apporte un support limité à /XInclude/ (mécanisme de fusion) mais requiert une étape additionnelle pour
|
||||||
|
réaliser l'inclusion.
|
||||||
|
7. Il s'agit de fonctionnalités mais peuvent introduire des failles supplémentaires.
|
||||||
|
|
||||||
|
|
||||||
|
* Références
|
||||||
|
* [[https://github.com/tiran/defusedxml][Github]]
|
96
20220319091825-anki.org
Normal file
96
20220319091825-anki.org
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: 97d8c2d9-a539-4f0b-ad2e-953bf7845e8c
|
||||||
|
:mtime: 20220319160846
|
||||||
|
:ctime: 20220319091825
|
||||||
|
:END:
|
||||||
|
#+title: anki
|
||||||
|
|
||||||
|
* Introduction
|
||||||
|
TODO
|
||||||
|
|
||||||
|
* Installer son serveur Anki
|
||||||
|
** Howto
|
||||||
|
*** On the server:
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
# Get last version source code.
|
||||||
|
cd /opt/
|
||||||
|
ROOT=/opt/anki-sync-server
|
||||||
|
mkdir ${ROOT}
|
||||||
|
chown ubuntu ${ROOT}
|
||||||
|
git clone https://github.com/ankicommunity/anki-sync-server.git
|
||||||
|
cd ${ROOT}
|
||||||
|
git checkout tags/v2.3.0
|
||||||
|
|
||||||
|
# Prépare virtual environment.
|
||||||
|
PATH=/home/ubuntu/.local/bin:$PATH
|
||||||
|
virtualenv .
|
||||||
|
. bin/activate
|
||||||
|
make init
|
||||||
|
|
||||||
|
# Create first user
|
||||||
|
./src/ankisyncctl.py adduser <user>
|
||||||
|
|
||||||
|
# Edit daemon config file.
|
||||||
|
CONFIG_PATH=${ROOT}/src/ankisyncd.conf
|
||||||
|
sed -i 's/port = 27701/port = 27702/' ${CONFIG_PATH}
|
||||||
|
sed -i 's/host = 0.0.0.0/host = 127.0.0.1/' ${CONFIG_PATH}
|
||||||
|
|
||||||
|
# Configure ngingx
|
||||||
|
cat >/etc/nginx/sites-available/anki-sync-server <<EOF
|
||||||
|
server {
|
||||||
|
server_name anki.adrien.run;
|
||||||
|
|
||||||
|
# Increase timeouts for XXL collections through slow bandwidth
|
||||||
|
proxy_read_timeout 3000;
|
||||||
|
proxy_connect_timeout 3000;
|
||||||
|
proxy_send_timeout 3000;
|
||||||
|
|
||||||
|
# log files
|
||||||
|
access_log /var/log/nginx/anki-sync-server.access.log;
|
||||||
|
error_log /var/log/nginx/anki-sync-server.error.log;
|
||||||
|
|
||||||
|
# Handle / requests
|
||||||
|
location / {
|
||||||
|
proxy_http_version 1.0;
|
||||||
|
proxy_pass http://127.0.0.1:27702/;
|
||||||
|
client_max_body_size 222M;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
ln -s /etc/nginx/sites-available/anki-sync-server /etc/nginx/sites-enabled/
|
||||||
|
systemctl reload nginx
|
||||||
|
|
||||||
|
# Generate certificates signed by certbot
|
||||||
|
certbot --nginx -d anki.adrien.run
|
||||||
|
systemctl reload nginx
|
||||||
|
|
||||||
|
# Add systemd service
|
||||||
|
cat>/etc/systemd/system/anki-sync-server.service <<EOF
|
||||||
|
Description=Anki sync server
|
||||||
|
After=syslog.target network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/opt/anki-sync-server
|
||||||
|
ExecStart=/opt/anki-sync-server/bin/python /opt/anki-sync-server/src/ankisyncd/__main__.py
|
||||||
|
Restart=on-abort
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl enable anki-sync-server.service
|
||||||
|
systemctl start anki-sync-server.service
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
*** For AnkiDroid:
|
||||||
|
Update configuration (in menu parameters/advanced/Custom sync server):
|
||||||
|
* URL: https://anki.adrien.run
|
||||||
|
* Media URL: https://anki.adrien.run/msync
|
||||||
|
|
||||||
|
*** For Anki2.1
|
||||||
|
Cf. https://github.com/ankicommunity/anki-sync-server#anki-21
|
||||||
|
|
||||||
|
** Références
|
||||||
|
* [[https://github.com/ankicommunity/anki-sync-server][Github]]
|
||||||
|
|
28
20220319131922-verrou_bash.org
Normal file
28
20220319131922-verrou_bash.org
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: 7052d327-0b67-40f6-a581-46df621cddb9
|
||||||
|
:mtime: 20220319133448
|
||||||
|
:ctime: 20220319131922
|
||||||
|
:END:
|
||||||
|
#+title: verrou-bash
|
||||||
|
|
||||||
|
* Verrou (lock) en sh
|
||||||
|
** Utilisation de /flock/
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
LOCK_PATH=/var/tmp/testlock.lock
|
||||||
|
exec 100>${LOCK_PATH} || exit 1
|
||||||
|
flock 100 || exit 1
|
||||||
|
|
||||||
|
echo "Doing some stuff…"
|
||||||
|
echo "Sleeping for 30 seconds…"
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
trap "rm -f ${LOCK_PATH}" EXIT
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
Quelques options :
|
||||||
|
* ~-w 10~ pour définir un timeout à ~flock~, ici 10 secondes.
|
||||||
|
* ~-n~ pour que ~flock~ n'attende pas si le verrou est pris.
|
||||||
|
|
||||||
|
* Références
|
||||||
|
* [[https://www.putorius.net/lock-files-bash-scripts.html][Using Lock Files for Job Control in Bash Scripts - Putorius]]
|
||||||
|
* [[https://linux.die.net/man/1/flock][Man flock]]
|
Reference in New Issue
Block a user