<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.johnlradford.io/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Admin</id>
	<title>John&#039;s Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.johnlradford.io/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Admin"/>
	<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Special:Contributions/Admin"/>
	<updated>2026-05-06T01:10:39Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=82</id>
		<title>FreeIPA - Identity Management</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=82"/>
		<updated>2025-10-25T19:25:49Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png&lt;br /&gt;
&lt;br /&gt;
FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.&lt;br /&gt;
&lt;br /&gt;
== How it Works ==&lt;br /&gt;
&lt;br /&gt;
Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.&lt;br /&gt;
&lt;br /&gt;
Access to hosts on the network are controlled via Host Based Access (HBA) Control Rules, which say what users are allowed access (via ssh) to what hosts.&lt;br /&gt;
&lt;br /&gt;
== Restarting All IPA Services ==&lt;br /&gt;
&lt;br /&gt;
You can use the command below to restart all FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
 sudo ipactl restart&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a systemd daemon for the main ipa service.&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl restart ipa&lt;br /&gt;
&lt;br /&gt;
== Resetting The Admin Password ==&lt;br /&gt;
&lt;br /&gt;
I&#039;ve had to do this once when restoring from a backup after changing the admin pass and loosing the old one. So I might have to do it again some day.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@freeipa:~# export LDAPTLS_CACERT=/etc/ipa/ca.crt&lt;br /&gt;
root@freeipa:~# ldappasswd -ZZ -D &#039;cn=directory manager&#039; -W -S uid=admin,cn=users,cn=accounts,dc=yourdomain,dc=net -H ldap://freeipa.yourdomain.net&lt;br /&gt;
New password: &lt;br /&gt;
Re-enter new password: &lt;br /&gt;
Enter LDAP Password: &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;Enter LDAP Password:&amp;lt;/code&amp;gt; use the Directory Manager password there (aka ldap admin). &lt;br /&gt;
&lt;br /&gt;
[https://serverfault.com/questions/731024/freeipa-admin-password-reset Source]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s Encrypt SSL Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Overview ===&lt;br /&gt;
&lt;br /&gt;
My FreeIPA server uses Let&#039;s Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
Here are the instructions for setting up a 3rd party cert for the ldap server &amp;amp; https web interface.&lt;br /&gt;
&lt;br /&gt;
https://www.freeipa.org/page/Using_3rd_part_certificates_for_HTTP/LDAP&lt;br /&gt;
&lt;br /&gt;
To get the CA certs loaded for LE see the section below.&lt;br /&gt;
&lt;br /&gt;
=== Adding Let&#039;s Encrypt CA Authorities ===&lt;br /&gt;
&lt;br /&gt;
I&#039;m using let&#039;s encrypt for the certs for the FreeIPA server. Because of how SSL works, FreeIPA will not accept the LE certs unless it has the CA certs too. This is how you can add a CA cert for LE in Fedora/FreeIPA.&lt;br /&gt;
&lt;br /&gt;
Where it started: I found the basic commands on [https://gist.github.com/lijikun/8b2b3350bce9aed7df3009e76541929c this github writeup link] and modified them.&lt;br /&gt;
&lt;br /&gt;
My Commands to add the R3 CA Authority.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
ipa-cacert-manage install lets-encrypt-r3.pem -n R3 -t C,,&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Found the latest ca cert file here: https://letsencrypt.org/certificates/&lt;br /&gt;
&lt;br /&gt;
Then I was able to use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; to install the cert.&lt;br /&gt;
&lt;br /&gt;
 ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Update&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: Needs even more cert authorities.&lt;br /&gt;
&lt;br /&gt;
Made / borrowed this script do get them all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Fetches LE CA certs for FreeIPA &amp;amp; runs update-ca-certificates.&lt;br /&gt;
# John R., Oct. 2024.&lt;br /&gt;
&lt;br /&gt;
[[ $EUID -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;Run as root!&amp;quot; &amp;amp;&amp;amp; exit 23&lt;br /&gt;
&lt;br /&gt;
set -x&lt;br /&gt;
if ! [[ -d /etc/pki/ca-trust/source/anchors ]]; then&lt;br /&gt;
    mkdir -p /etc/pki/ca-trust/source/anchors&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrgrootx1.crt https://letsencrypt.org/certs/isrgrootx1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrg-root-x2.crt https://letsencrypt.org/certs/isrg-root-x2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r3.crt https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e1.crt https://letsencrypt.org/certs/lets-encrypt-e1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r4.crt https://letsencrypt.org/certs/lets-encrypt-r4.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e2.crt https://letsencrypt.org/certs/lets-encrypt-e2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e5.crt https://letsencrypt.org/certs/2024/e5.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e6.crt https://letsencrypt.org/certs/2024/e6.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e7.crt https://letsencrypt.org/certs/2024/e7.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e8.crt https://letsencrypt.org/certs/2024/e8.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r10.crt https://letsencrypt.org/certs/2024/r10.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r11.crt https://letsencrypt.org/certs/2024/r11.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r12.crt https://letsencrypt.org/certs/2024/r12.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r13.crt https://letsencrypt.org/certs/2024/r13.pem&lt;br /&gt;
&lt;br /&gt;
# Update at os level&lt;br /&gt;
update-ca-trust&lt;br /&gt;
&lt;br /&gt;
# Update certs for ipa&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&lt;br /&gt;
# List em cause why not&lt;br /&gt;
ipa-cacert-manage list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/freeipa/freeipa-letsencrypt/issues/25 Original Source]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BlueSquare23/Misc_Bash_Scripts/blob/master/fetch-ca-certs.sh Modified Version on my Github]&lt;br /&gt;
&lt;br /&gt;
=== Renewing an expired cert ===&lt;br /&gt;
&lt;br /&gt;
If the cert for the FreeIPA server expires you can still use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; tool to renew it, like you normally would. However, there&#039;s a catch. You have to prepend your command with the &amp;lt;code&amp;gt;faketime&amp;lt;/code&amp;gt; util and set the date to a time before when the current certificate expired.&lt;br /&gt;
&lt;br /&gt;
 EXPIRED!&lt;br /&gt;
 Not After: Mon, 25 Nov 2024 02:26:25 GMT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo faketime &#039;2024-11-24 08:15:42&#039; ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
Directory Manager password: &lt;br /&gt;
&lt;br /&gt;
Enter private key unlock password: &lt;br /&gt;
&lt;br /&gt;
Please restart ipa services after installing certificate (ipactl restart)&lt;br /&gt;
The ipa-server-certinstall command was successful&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just run &amp;lt;code&amp;gt;sudo ipactl restart&amp;lt;/code&amp;gt; to restart the FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Additional ==&lt;br /&gt;
&lt;br /&gt;
Check currently installed certs on Fedora with:&lt;br /&gt;
&lt;br /&gt;
 trust list --filter=ca-anchors&lt;br /&gt;
&lt;br /&gt;
See only Let&#039;s Encrypt and ISGR certs:&lt;br /&gt;
&lt;br /&gt;
 trust list --filter=ca-anchors | grep -E &#039;Let.s Encrypt|Internet Security Research&#039; -i -A 2 -B 3&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=81</id>
		<title>FreeIPA - Identity Management</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=81"/>
		<updated>2025-10-25T19:19:21Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png&lt;br /&gt;
&lt;br /&gt;
FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.&lt;br /&gt;
&lt;br /&gt;
== How it Works ==&lt;br /&gt;
&lt;br /&gt;
Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.&lt;br /&gt;
&lt;br /&gt;
Access to hosts on the network are controlled via Host Based Access (HBA) Control Rules, which say what users are allowed access (via ssh) to what hosts.&lt;br /&gt;
&lt;br /&gt;
== Restarting All IPA Services ==&lt;br /&gt;
&lt;br /&gt;
You can use the command below to restart all FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
 sudo ipactl restart&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a systemd daemon for the main ipa service.&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl restart ipa&lt;br /&gt;
&lt;br /&gt;
== Resetting The Admin Password ==&lt;br /&gt;
&lt;br /&gt;
I&#039;ve had to do this once when restoring from a backup after changing the admin pass and loosing the old one. So I might have to do it again some day.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@freeipa:~# export LDAPTLS_CACERT=/etc/ipa/ca.crt&lt;br /&gt;
root@freeipa:~# ldappasswd -ZZ -D &#039;cn=directory manager&#039; -W -S uid=admin,cn=users,cn=accounts,dc=yourdomain,dc=net -H ldap://freeipa.yourdomain.net&lt;br /&gt;
New password: &lt;br /&gt;
Re-enter new password: &lt;br /&gt;
Enter LDAP Password: &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;Enter LDAP Password:&amp;lt;/code&amp;gt; use the Directory Manager password there (aka ldap admin). &lt;br /&gt;
&lt;br /&gt;
[https://serverfault.com/questions/731024/freeipa-admin-password-reset Source]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s Encrypt SSL Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Overview ===&lt;br /&gt;
&lt;br /&gt;
My FreeIPA server uses Let&#039;s Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
Here are the instructions for setting up a 3rd party cert for the ldap server &amp;amp; https web interface.&lt;br /&gt;
&lt;br /&gt;
https://www.freeipa.org/page/Using_3rd_part_certificates_for_HTTP/LDAP&lt;br /&gt;
&lt;br /&gt;
To get the CA certs loaded for LE see the section below.&lt;br /&gt;
&lt;br /&gt;
=== Adding Let&#039;s Encrypt CA Authorities ===&lt;br /&gt;
&lt;br /&gt;
I&#039;m using let&#039;s encrypt for the certs for the FreeIPA server. Because of how SSL works, FreeIPA will not accept the LE certs unless it has the CA certs too. This is how you can add a CA cert for LE in Fedora/FreeIPA.&lt;br /&gt;
&lt;br /&gt;
Where it started: I found the basic commands on [https://gist.github.com/lijikun/8b2b3350bce9aed7df3009e76541929c this github writeup link] and modified them.&lt;br /&gt;
&lt;br /&gt;
My Commands to add the R3 CA Authority.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
ipa-cacert-manage install lets-encrypt-r3.pem -n R3 -t C,,&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Found the latest ca cert file here: https://letsencrypt.org/certificates/&lt;br /&gt;
&lt;br /&gt;
Then I was able to use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; to install the cert.&lt;br /&gt;
&lt;br /&gt;
 ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Update&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: Needs even more cert authorities.&lt;br /&gt;
&lt;br /&gt;
Made / borrowed this script do get them all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Fetches LE CA certs for FreeIPA &amp;amp; runs update-ca-certificates.&lt;br /&gt;
# John R., Oct. 2024.&lt;br /&gt;
&lt;br /&gt;
[[ $EUID -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;Run as root!&amp;quot; &amp;amp;&amp;amp; exit 23&lt;br /&gt;
&lt;br /&gt;
set -x&lt;br /&gt;
if ! [[ -d /etc/pki/ca-trust/source/anchors ]]; then&lt;br /&gt;
    mkdir -p /etc/pki/ca-trust/source/anchors&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrgrootx1.crt https://letsencrypt.org/certs/isrgrootx1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrg-root-x2.crt https://letsencrypt.org/certs/isrg-root-x2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r3.crt https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e1.crt https://letsencrypt.org/certs/lets-encrypt-e1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r4.crt https://letsencrypt.org/certs/lets-encrypt-r4.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e2.crt https://letsencrypt.org/certs/lets-encrypt-e2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e5.crt https://letsencrypt.org/certs/2024/e5.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e6.crt https://letsencrypt.org/certs/2024/e6.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e7.crt https://letsencrypt.org/certs/2024/e7.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e8.crt https://letsencrypt.org/certs/2024/e8.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r10.crt https://letsencrypt.org/certs/2024/r10.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r11.crt https://letsencrypt.org/certs/2024/r11.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r12.crt https://letsencrypt.org/certs/2024/r12.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r13.crt https://letsencrypt.org/certs/2024/r13.pem&lt;br /&gt;
&lt;br /&gt;
# Update at os level&lt;br /&gt;
update-ca-trust&lt;br /&gt;
&lt;br /&gt;
# Update certs for ipa&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&lt;br /&gt;
# List em cause why not&lt;br /&gt;
ipa-cacert-manage list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/freeipa/freeipa-letsencrypt/issues/25 Original Source]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BlueSquare23/Misc_Bash_Scripts/blob/master/fetch-ca-certs.sh Modified Version on my Github]&lt;br /&gt;
&lt;br /&gt;
=== Renewing an expired cert ===&lt;br /&gt;
&lt;br /&gt;
If the cert for the FreeIPA server expires you can still use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; tool to renew it, like you normally would. However, there&#039;s a catch. You have to prepend your command with the &amp;lt;code&amp;gt;faketime&amp;lt;/code&amp;gt; util and set the date to a time before when the current certificate expired.&lt;br /&gt;
&lt;br /&gt;
 EXPIRED!&lt;br /&gt;
 Not After: Mon, 25 Nov 2024 02:26:25 GMT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo faketime &#039;2024-11-24 08:15:42&#039; ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
Directory Manager password: &lt;br /&gt;
&lt;br /&gt;
Enter private key unlock password: &lt;br /&gt;
&lt;br /&gt;
Please restart ipa services after installing certificate (ipactl restart)&lt;br /&gt;
The ipa-server-certinstall command was successful&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just run &amp;lt;code&amp;gt;sudo ipactl restart&amp;lt;/code&amp;gt; to restart the FreeIPA services.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=80</id>
		<title>FreeIPA - Identity Management</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=80"/>
		<updated>2025-10-25T19:17:21Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png&lt;br /&gt;
&lt;br /&gt;
FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.&lt;br /&gt;
&lt;br /&gt;
== How it Works ==&lt;br /&gt;
&lt;br /&gt;
Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.&lt;br /&gt;
&lt;br /&gt;
Access to hosts on the network are controlled via Host Based Access (HBA) Control Rules, which say what users are allowed access (via ssh) to what hosts.&lt;br /&gt;
&lt;br /&gt;
== Restarting All IPA Services ==&lt;br /&gt;
&lt;br /&gt;
You can use the command below to restart all FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
 sudo ipactl restart&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a systemd daemon for the main ipa service.&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl restart ipa&lt;br /&gt;
&lt;br /&gt;
== Resetting The Admin Password ==&lt;br /&gt;
&lt;br /&gt;
I&#039;ve had to do this once when restoring from a backup after changing the admin pass and loosing the old one. So I might have to do it again some day.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@freeipa:~# export LDAPTLS_CACERT=/etc/ipa/ca.crt&lt;br /&gt;
root@freeipa:~# ldappasswd -ZZ -D &#039;cn=directory manager&#039; -W -S uid=admin,cn=users,cn=accounts,dc=yourdomain,dc=net -H ldap://freeipa.yourdomain.net&lt;br /&gt;
New password: &lt;br /&gt;
Re-enter new password: &lt;br /&gt;
Enter LDAP Password: &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;Enter LDAP Password:&amp;lt;/code&amp;gt; use the Directory Manager password there (aka ldap admin). &lt;br /&gt;
&lt;br /&gt;
[https://serverfault.com/questions/731024/freeipa-admin-password-reset Source]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s Encrypt SSL Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Overview ===&lt;br /&gt;
&lt;br /&gt;
My FreeIPA server uses Let&#039;s Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
Here are the instructions for setting up a 3rd party cert for the ldap server &amp;amp; https web interface.&lt;br /&gt;
&lt;br /&gt;
https://www.freeipa.org/page/Using_3rd_part_certificates_for_HTTP/LDAP&lt;br /&gt;
&lt;br /&gt;
To get the CA certs loaded for LE see the section below.&lt;br /&gt;
&lt;br /&gt;
=== Adding Let&#039;s Encrypt CA Authorities ===&lt;br /&gt;
&lt;br /&gt;
I&#039;m using let&#039;s encrypt for the certs for the FreeIPA server. Because of how SSL works, FreeIPA will not accept the LE certs unless it has the CA certs too. This is how you can add a CA cert for LE in Fedora/FreeIPA.&lt;br /&gt;
&lt;br /&gt;
Where it started: I found the basic commands on [https://gist.github.com/lijikun/8b2b3350bce9aed7df3009e76541929c this github writeup link] and modified them.&lt;br /&gt;
&lt;br /&gt;
My Commands to add the R3 CA Authority.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
ipa-cacert-manage install lets-encrypt-r3.pem -n R3 -t C,,&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Found the latest ca cert file here: https://letsencrypt.org/certificates/&lt;br /&gt;
&lt;br /&gt;
Then I was able to use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; to install the cert.&lt;br /&gt;
&lt;br /&gt;
 ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Update&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: Needs even more cert authorities.&lt;br /&gt;
&lt;br /&gt;
Made / borrowed this script do get them all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Fetches LE CA certs for FreeIPA &amp;amp; runs update-ca-certificates.&lt;br /&gt;
# John R., Oct. 2024.&lt;br /&gt;
&lt;br /&gt;
[[ $EUID -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;Run as root!&amp;quot; &amp;amp;&amp;amp; exit 23&lt;br /&gt;
&lt;br /&gt;
set -x&lt;br /&gt;
if ! [[ -d /etc/pki/ca-trust/source/anchors ]]; then&lt;br /&gt;
    mkdir -p /etc/pki/ca-trust/source/anchors&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrgrootx1.crt https://letsencrypt.org/certs/isrgrootx1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrg-root-x2.crt https://letsencrypt.org/certs/isrg-root-x2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r3.crt https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e1.crt https://letsencrypt.org/certs/lets-encrypt-e1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r4.crt https://letsencrypt.org/certs/lets-encrypt-r4.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e2.crt https://letsencrypt.org/certs/lets-encrypt-e2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e5.crt https://letsencrypt.org/certs/2024/e5.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e6.crt https://letsencrypt.org/certs/2024/e6.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e7.crt https://letsencrypt.org/certs/2024/e7.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e8.crt https://letsencrypt.org/certs/2024/e8.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r10.crt https://letsencrypt.org/certs/2024/r10.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r11.crt https://letsencrypt.org/certs/2024/r11.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r12.crt https://letsencrypt.org/certs/2024/r12.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r13.crt https://letsencrypt.org/certs/2024/r13.pem&lt;br /&gt;
&lt;br /&gt;
# Update as os level&lt;br /&gt;
update-ca-trust&lt;br /&gt;
&lt;br /&gt;
# Update certs for ipa&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&lt;br /&gt;
# List em cause why not&lt;br /&gt;
ipa-cacert-manage list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/freeipa/freeipa-letsencrypt/issues/25 Original Source]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BlueSquare23/Misc_Bash_Scripts/blob/master/fetch-ca-certs.sh Modified Version on my Github]&lt;br /&gt;
&lt;br /&gt;
=== Renewing an expired cert ===&lt;br /&gt;
&lt;br /&gt;
If the cert for the FreeIPA server expires you can still use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; tool to renew it, like you normally would. However, there&#039;s a catch. You have to prepend your command with the &amp;lt;code&amp;gt;faketime&amp;lt;/code&amp;gt; util and set the date to a time before when the current certificate expired.&lt;br /&gt;
&lt;br /&gt;
 EXPIRED!&lt;br /&gt;
 Not After: Mon, 25 Nov 2024 02:26:25 GMT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo faketime &#039;2024-11-24 08:15:42&#039; ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
Directory Manager password: &lt;br /&gt;
&lt;br /&gt;
Enter private key unlock password: &lt;br /&gt;
&lt;br /&gt;
Please restart ipa services after installing certificate (ipactl restart)&lt;br /&gt;
The ipa-server-certinstall command was successful&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just run &amp;lt;code&amp;gt;sudo ipactl restart&amp;lt;/code&amp;gt; to restart the FreeIPA services.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=79</id>
		<title>FreeIPA - Identity Management</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=79"/>
		<updated>2025-10-25T19:16:24Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png&lt;br /&gt;
&lt;br /&gt;
FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.&lt;br /&gt;
&lt;br /&gt;
== How it Works ==&lt;br /&gt;
&lt;br /&gt;
Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.&lt;br /&gt;
&lt;br /&gt;
Access to hosts on the network are controlled via Host Based Access (HBA) Control Rules, which say what users are allowed access (via ssh) to what hosts.&lt;br /&gt;
&lt;br /&gt;
== Restarting All IPA Services ==&lt;br /&gt;
&lt;br /&gt;
You can use the command below to restart all FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
 sudo ipactl restart&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a systemd daemon for the main ipa service.&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl restart ipa&lt;br /&gt;
&lt;br /&gt;
== Resetting The Admin Password ==&lt;br /&gt;
&lt;br /&gt;
I&#039;ve had to do this once when restoring from a backup after changing the admin pass and loosing the old one. So I might have to do it again some day.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@freeipa:~# export LDAPTLS_CACERT=/etc/ipa/ca.crt&lt;br /&gt;
root@freeipa:~# ldappasswd -ZZ -D &#039;cn=directory manager&#039; -W -S uid=admin,cn=users,cn=accounts,dc=yourdomain,dc=net -H ldap://freeipa.yourdomain.net&lt;br /&gt;
New password: &lt;br /&gt;
Re-enter new password: &lt;br /&gt;
Enter LDAP Password: &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;Enter LDAP Password:&amp;lt;/code&amp;gt; use the Directory Manager password there (aka ldap admin). &lt;br /&gt;
&lt;br /&gt;
[https://serverfault.com/questions/731024/freeipa-admin-password-reset Source]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s Encrypt SSL Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Overview ===&lt;br /&gt;
&lt;br /&gt;
My FreeIPA server uses Let&#039;s Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
Here are the instructions for setting up a 3rd party cert for the ldap server &amp;amp; https web interface.&lt;br /&gt;
&lt;br /&gt;
https://www.freeipa.org/page/Using_3rd_part_certificates_for_HTTP/LDAP&lt;br /&gt;
&lt;br /&gt;
To get the CA certs loaded for LE see the section below.&lt;br /&gt;
&lt;br /&gt;
=== Adding Let&#039;s Encrypt CA Authorities ===&lt;br /&gt;
&lt;br /&gt;
I&#039;m using let&#039;s encrypt for the certs for the FreeIPA server. Because of how SSL works, FreeIPA will not accept the LE certs unless it has the CA certs too. This is how you can add a CA cert for LE in Fedora/FreeIPA.&lt;br /&gt;
&lt;br /&gt;
Where it started: I found the basic commands on [https://gist.github.com/lijikun/8b2b3350bce9aed7df3009e76541929c this github writeup link] and modified them.&lt;br /&gt;
&lt;br /&gt;
My Commands to add the R3 CA Authority.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
ipa-cacert-manage install lets-encrypt-r3.pem -n R3 -t C,,&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Found the latest ca cert file here: https://letsencrypt.org/certificates/&lt;br /&gt;
&lt;br /&gt;
Then I was able to use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; to install the cert.&lt;br /&gt;
&lt;br /&gt;
 ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Update&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: Needs even more cert authorities.&lt;br /&gt;
&lt;br /&gt;
Made / borrowed this script do get them all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Fetches LE CA certs for FreeIPA &amp;amp; runs update-ca-certificates.&lt;br /&gt;
# John R., Oct. 2024.&lt;br /&gt;
&lt;br /&gt;
[[ $EUID -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;Run as root!&amp;quot; &amp;amp;&amp;amp; exit 23&lt;br /&gt;
&lt;br /&gt;
set -x&lt;br /&gt;
if ! [[ -d /usr/local/share/ca-certificates/extra ]]; then&lt;br /&gt;
    mkdir -p /usr/local/share/ca-certificates/extra&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrgrootx1.crt https://letsencrypt.org/certs/isrgrootx1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/isrg-root-x2.crt https://letsencrypt.org/certs/isrg-root-x2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r3.crt https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e1.crt https://letsencrypt.org/certs/lets-encrypt-e1.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-r4.crt https://letsencrypt.org/certs/lets-encrypt-r4.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/lets-encrypt-e2.crt https://letsencrypt.org/certs/lets-encrypt-e2.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e5.crt https://letsencrypt.org/certs/2024/e5.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e6.crt https://letsencrypt.org/certs/2024/e6.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e7.crt https://letsencrypt.org/certs/2024/e7.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/e8.crt https://letsencrypt.org/certs/2024/e8.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r10.crt https://letsencrypt.org/certs/2024/r10.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r11.crt https://letsencrypt.org/certs/2024/r11.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r12.crt https://letsencrypt.org/certs/2024/r12.pem&lt;br /&gt;
wget -O /etc/pki/ca-trust/source/anchors/r13.crt https://letsencrypt.org/certs/2024/r13.pem&lt;br /&gt;
&lt;br /&gt;
# Update as os level&lt;br /&gt;
update-ca-trust&lt;br /&gt;
&lt;br /&gt;
# Update certs for ipa&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&lt;br /&gt;
# List em cause why not&lt;br /&gt;
ipa-cacert-manage list&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/freeipa/freeipa-letsencrypt/issues/25 Original Source]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BlueSquare23/Misc_Bash_Scripts/blob/master/fetch-ca-certs.sh Modified Version on my Github]&lt;br /&gt;
&lt;br /&gt;
=== Renewing an expired cert ===&lt;br /&gt;
&lt;br /&gt;
If the cert for the FreeIPA server expires you can still use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; tool to renew it, like you normally would. However, there&#039;s a catch. You have to prepend your command with the &amp;lt;code&amp;gt;faketime&amp;lt;/code&amp;gt; util and set the date to a time before when the current certificate expired.&lt;br /&gt;
&lt;br /&gt;
 EXPIRED!&lt;br /&gt;
 Not After: Mon, 25 Nov 2024 02:26:25 GMT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo faketime &#039;2024-11-24 08:15:42&#039; ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
Directory Manager password: &lt;br /&gt;
&lt;br /&gt;
Enter private key unlock password: &lt;br /&gt;
&lt;br /&gt;
Please restart ipa services after installing certificate (ipactl restart)&lt;br /&gt;
The ipa-server-certinstall command was successful&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just run &amp;lt;code&amp;gt;sudo ipactl restart&amp;lt;/code&amp;gt; to restart the FreeIPA services.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=78</id>
		<title>Virsh list all in json</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=78"/>
		<updated>2025-01-16T18:44:45Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; command will list all virsh guests in json.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;[ $(virsh list --all|grep -Ev &#039;Id|----&#039;|awk &#039;{print &amp;quot;{ \&amp;quot;id\&amp;quot;: \&amp;quot;&amp;quot;$1&amp;quot;\&amp;quot;, \&amp;quot;name\&amp;quot;: \&amp;quot;&amp;quot;$2&amp;quot;\&amp;quot;, \&amp;quot;state\&amp;quot;: \&amp;quot;&amp;quot;$3 $4&amp;quot;\&amp;quot;},&amp;quot; }&#039;|head -n -1) {} ]&amp;quot;|jq -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot; line&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;38&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Mac&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;39&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Dennis&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;40&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Charlie&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# TODO: Come back and redo this using the &amp;lt;code&amp;gt;columns&amp;lt;/code&amp;gt; utility.&lt;br /&gt;
https://www.youtube.com/watch?v=uL7KvRskeog&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=77</id>
		<title>FreeIPA - Identity Management</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=77"/>
		<updated>2024-11-28T22:09:36Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png&lt;br /&gt;
&lt;br /&gt;
FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.&lt;br /&gt;
&lt;br /&gt;
== How it Works ==&lt;br /&gt;
&lt;br /&gt;
Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.&lt;br /&gt;
&lt;br /&gt;
Access to hosts on the network are controlled via Host Based Access (HBA) Control Rules, which say what users are allowed access (via ssh) to what hosts.&lt;br /&gt;
&lt;br /&gt;
== Restarting All IPA Services ==&lt;br /&gt;
&lt;br /&gt;
You can use the command below to restart all FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
 sudo ipactl restart&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a systemd daemon for the main ipa service.&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl restart ipa&lt;br /&gt;
&lt;br /&gt;
== Resetting The Admin Password ==&lt;br /&gt;
&lt;br /&gt;
I&#039;ve had to do this once when restoring from a backup after changing the admin pass and loosing the old one. So I might have to do it again some day.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@freeipa:~# export LDAPTLS_CACERT=/etc/ipa/ca.crt&lt;br /&gt;
root@freeipa:~# ldappasswd -ZZ -D &#039;cn=directory manager&#039; -W -S uid=admin,cn=users,cn=accounts,dc=yourdomain,dc=net -H ldap://freeipa.yourdomain.net&lt;br /&gt;
New password: &lt;br /&gt;
Re-enter new password: &lt;br /&gt;
Enter LDAP Password: &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;Enter LDAP Password:&amp;lt;/code&amp;gt; use the Directory Manager password there (aka ldap admin). &lt;br /&gt;
&lt;br /&gt;
[https://serverfault.com/questions/731024/freeipa-admin-password-reset Source]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s Encrypt SSL Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Overview ===&lt;br /&gt;
&lt;br /&gt;
My FreeIPA server uses Let&#039;s Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
Here are the instructions for setting up a 3rd party cert for the ldap server &amp;amp; https web interface.&lt;br /&gt;
&lt;br /&gt;
https://www.freeipa.org/page/Using_3rd_part_certificates_for_HTTP/LDAP&lt;br /&gt;
&lt;br /&gt;
To get the CA certs loaded for LE see the section below.&lt;br /&gt;
&lt;br /&gt;
=== Adding Let&#039;s Encrypt CA Authorities ===&lt;br /&gt;
&lt;br /&gt;
I&#039;m using let&#039;s encrypt for the certs for the FreeIPA server. Because of how SSL works, FreeIPA will not accept the LE certs unless it has the CA certs too. This is how you can add a CA cert for LE in Fedora/FreeIPA.&lt;br /&gt;
&lt;br /&gt;
Where it started: I found the basic commands on [https://gist.github.com/lijikun/8b2b3350bce9aed7df3009e76541929c this github writeup link] and modified them.&lt;br /&gt;
&lt;br /&gt;
My Commands to add the R3 CA Authority.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
ipa-cacert-manage install lets-encrypt-r3.pem -n R3 -t C,,&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Found the latest ca cert file here: https://letsencrypt.org/certificates/&lt;br /&gt;
&lt;br /&gt;
Then I was able to use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; to install the cert.&lt;br /&gt;
&lt;br /&gt;
 ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Update&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: Needs even more cert authorities.&lt;br /&gt;
&lt;br /&gt;
Made / borrowed this script do get them all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Fetches LE CA certs for FreeIPA &amp;amp; runs update-ca-certificates.&lt;br /&gt;
# John R., Oct. 2024.&lt;br /&gt;
&lt;br /&gt;
[[ $EUID -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;Run as root!&amp;quot; &amp;amp;&amp;amp; exit 23&lt;br /&gt;
&lt;br /&gt;
set -x&lt;br /&gt;
if ! [[ -d /usr/local/share/ca-certificates/extra ]]; then&lt;br /&gt;
    mkdir -p /usr/local/share/ca-certificates/extra&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/isrgrootx1.crt https://letsencrypt.org/certs/isrgrootx1.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/isrg-root-x2.crt https://letsencrypt.org/certs/isrg-root-x2.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-r3.crt https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-e1.crt https://letsencrypt.org/certs/lets-encrypt-e1.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-r4.crt https://letsencrypt.org/certs/lets-encrypt-r4.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-e2.crt https://letsencrypt.org/certs/lets-encrypt-e2.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/e5.crt https://letsencrypt.org/certs/2024/e5.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/e6.crt https://letsencrypt.org/certs/2024/e6.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/r10.crt https://letsencrypt.org/certs/2024/r10.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/r11.crt https://letsencrypt.org/certs/2024/r11.pem&lt;br /&gt;
&lt;br /&gt;
update-ca-certificates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/freeipa/freeipa-letsencrypt/issues/25 Original Source]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BlueSquare23/Misc_Bash_Scripts/blob/master/fetch-ca-certs.sh Modified Version on my Github]&lt;br /&gt;
&lt;br /&gt;
=== Renewing an expired cert ===&lt;br /&gt;
&lt;br /&gt;
If the cert for the FreeIPA server expires you can still use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; tool to renew it, like you normally would. However, there&#039;s a catch. You have to prepend your command with the &amp;lt;code&amp;gt;faketime&amp;lt;/code&amp;gt; util and set the date to a time before when the current certificate expired.&lt;br /&gt;
&lt;br /&gt;
 EXPIRED!&lt;br /&gt;
 Not After: Mon, 25 Nov 2024 02:26:25 GMT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo faketime &#039;2024-11-24 08:15:42&#039; ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
Directory Manager password: &lt;br /&gt;
&lt;br /&gt;
Enter private key unlock password: &lt;br /&gt;
&lt;br /&gt;
Please restart ipa services after installing certificate (ipactl restart)&lt;br /&gt;
The ipa-server-certinstall command was successful&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just run &amp;lt;code&amp;gt;sudo ipactl restart&amp;lt;/code&amp;gt; to restart the FreeIPA services.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=76</id>
		<title>Virsh list all in json</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=76"/>
		<updated>2024-11-28T21:44:44Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; command will list all virsh guests in json.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;[ $(virsh list --all|grep -Ev &#039;Id|----&#039;|awk &#039;{print &amp;quot;{ \&amp;quot;id\&amp;quot;: \&amp;quot;&amp;quot;$1&amp;quot;\&amp;quot;, \&amp;quot;name\&amp;quot;: \&amp;quot;&amp;quot;$2&amp;quot;\&amp;quot;, \&amp;quot;state\&amp;quot;: \&amp;quot;&amp;quot;$3 $4&amp;quot;\&amp;quot;},&amp;quot; }&#039;|head -n -1) {} ]&amp;quot;|jq -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot; line&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;38&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Mac&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;39&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Dennis&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;40&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Charlie&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=75</id>
		<title>Virsh list all in json</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=75"/>
		<updated>2024-11-28T21:42:00Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; command will list all virsh guests in json.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
echo &amp;quot;[ $(virsh list --all|grep -Ev &#039;Id|----&#039;|awk &#039;{print &amp;quot;{ \&amp;quot;id\&amp;quot;: \&amp;quot;&amp;quot;$1&amp;quot;\&amp;quot;, \&amp;quot;name\&amp;quot;: \&amp;quot;&amp;quot;$2&amp;quot;\&amp;quot;, \&amp;quot;state\&amp;quot;: \&amp;quot;&amp;quot;$3 $4&amp;quot;\&amp;quot;},&amp;quot; }&#039;|head -n -1) {} ]&amp;quot;|jq -r&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;json&amp;quot; line&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;38&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Mac&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;39&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Dennis&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;40&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Charlie&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Sending_an_Email_with_Python3_via_smtplib&amp;diff=74</id>
		<title>Sending an Email with Python3 via smtplib</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Sending_an_Email_with_Python3_via_smtplib&amp;diff=74"/>
		<updated>2024-11-28T21:40:33Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;It possible to use the module [https://docs.python.org/3/library/smtplib.html &amp;lt;code&amp;gt;smtplib&amp;lt;/code&amp;gt;] to send an Email with python3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
&lt;br /&gt;
import smtplib &lt;br /&gt;
from email.message import EmailMessage&lt;br /&gt;
&lt;br /&gt;
to_addr = &#039;to@example.com&#039;&lt;br /&gt;
from_addr = &#039;from@example.com&#039;&lt;br /&gt;
mail_server = &#039;mail.example.com&#039;&lt;br /&gt;
passwd = &#039;YOUR_MAILBOX_PASSWORD&#039;&lt;br /&gt;
&lt;br /&gt;
message = EmailMessage()&lt;br /&gt;
message[&amp;quot;To&amp;quot;]      = to_addr&lt;br /&gt;
message[&amp;quot;From&amp;quot;]    = from_addr&lt;br /&gt;
message[&amp;quot;Subject&amp;quot;] = &#039;Sent with Python &amp;amp; Smtplib&#039;&lt;br /&gt;
message.set_payload(&#039;This is a test message!&#039;)&lt;br /&gt;
&lt;br /&gt;
s = smtplib.SMTP_SSL(mail_server, 465)&lt;br /&gt;
s.login(to_addr, passwd)&lt;br /&gt;
s.sendmail(to_addr, from_addr, message.as_string())&lt;br /&gt;
s.quit()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Sending an Email with...]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Bats_-_Bash_Automated_Testing_System&amp;diff=73</id>
		<title>Bats - Bash Automated Testing System</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Bats_-_Bash_Automated_Testing_System&amp;diff=73"/>
		<updated>2024-11-28T21:39:39Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Bash Automated Testing System =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
Bats is a [https://testanything.org/ TAP-compliant] testing framework for Bash. It provides a simple way to verify that the UNIX programs you write behave as expected.&lt;br /&gt;
&lt;br /&gt;
A Bats test file is a Bash script with special syntax for defining test cases. Under the hood, each test case is just a function with a description.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/usr/bin/env bats&lt;br /&gt;
&lt;br /&gt;
@test &amp;amp;quot;addition using bc&amp;amp;quot; {&lt;br /&gt;
  result=&amp;amp;quot;$(echo 2+2 | bc)&amp;amp;quot;&lt;br /&gt;
  [ &amp;amp;quot;$result&amp;amp;quot; -eq 4 ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(The above overview section was stolen verbatim from [https://github.com/sstephenson/bats the main projects README]).&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
&lt;br /&gt;
=== Installing Locally ===&lt;br /&gt;
&lt;br /&gt;
The steps below are to install bats at a user level (ie. ~/bin ~/.local/lib). However, Bats can also be installed at a system level (ie. root install, /usr/local) or as a [https://opensource.com/article/19/2/testing-bash-bats submodule of a pre-existing git repository] for CI purposes.&lt;br /&gt;
&lt;br /&gt;
Run the commands below to install bats as well as the bats-assert helper library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir $HOME/.local/lib/bats&lt;br /&gt;
git clone https://github.com/ztombol/bats-support $HOME/.local/lib/bats/batscore&lt;br /&gt;
git clone https://github.com/ztombol/bats-assert $HOME/.local/lib/bats/batsassert&lt;br /&gt;
git clone --depth 1 https://github.com/sstephenson/bats $HOME/bats&lt;br /&gt;
cd $HOME/bats &amp;amp;amp;&amp;amp;amp; ./install.sh $HOME/ &amp;amp;amp;&amp;amp;amp; cd .. &amp;amp;amp;&amp;amp;amp; rm -rf bats&amp;lt;/pre&amp;gt;&lt;br /&gt;
== First Tests ==&lt;br /&gt;
&lt;br /&gt;
The examples below are two very simple bats test cases. They test whether or not the script&#039;s own file name exists and if the file name is &#039;test.bats&#039; (two tests it should always pass).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;test.bats&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/usr/bin/env bats&lt;br /&gt;
&lt;br /&gt;
setup() {&lt;br /&gt;
	# Import core and assert modules.&lt;br /&gt;
	load $HOME/.local/lib/bats/batscore/load.bash&lt;br /&gt;
	load $HOME/.local/lib/bats/batsassert/load.bash&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
@test &amp;quot;I exist,&amp;quot; {&lt;br /&gt;
	[ -e $BATS_TEST_FILENAME ]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
@test &#039;Therefore I am!&#039; {&lt;br /&gt;
	assert_equal &amp;quot;$(basename $BATS_TEST_FILENAME)&amp;quot; &#039;test.bats&#039;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Running the First Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./test.bats&lt;br /&gt;
 ✓ I exist!&lt;br /&gt;
 ✓ Therefore I am!&lt;br /&gt;
&lt;br /&gt;
2 tests, 0 failures&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Continued Documentation ==&lt;br /&gt;
&lt;br /&gt;
This project is documented pretty well in the following locations. The below docs are also responsible for a lot of the content presented above.&lt;br /&gt;
&lt;br /&gt;
Pick up where this note leaves off by [https://bats-core.readthedocs.io/en/stable/tutorial.html#your-first-test Reading the Docs on Bats].&lt;br /&gt;
&lt;br /&gt;
[https://github.com/sstephenson/bats/blob/master/README.md Main / Original Project README]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ztombol/bats-assert/blob/master/README.md Bats Assert README]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/ztombol/bats-support/blob/master/README.md Current / Bats Support Project Readme]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=72</id>
		<title>FreeIPA - Identity Management</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=72"/>
		<updated>2024-11-28T21:38:28Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png&lt;br /&gt;
&lt;br /&gt;
FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.&lt;br /&gt;
&lt;br /&gt;
== How it Works ==&lt;br /&gt;
&lt;br /&gt;
Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.&lt;br /&gt;
&lt;br /&gt;
Access to hosts on the network are controlled via Host Based Access (HBA) Control Rules, which say what users are allowed access (via ssh) to what hosts.&lt;br /&gt;
&lt;br /&gt;
== Restarting All IPA Services ==&lt;br /&gt;
&lt;br /&gt;
You can use the command below to restart all FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
 sudo ipactl restart&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a systemd daemon for the main ipa service.&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl restart ipa&lt;br /&gt;
&lt;br /&gt;
== Resetting The Admin Password ==&lt;br /&gt;
&lt;br /&gt;
I&#039;ve had to do this once when restoring from a backup after changing the admin pass and loosing the old one. So I might have to do it again some day.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@freeipa:~# export LDAPTLS_CACERT=/etc/ipa/ca.crt&lt;br /&gt;
root@freeipa:~# ldappasswd -ZZ -D &#039;cn=directory manager&#039; -W -S uid=admin,cn=users,cn=accounts,dc=yourdomain,dc=net -H ldap://freeipa.yourdomain.net&lt;br /&gt;
New password: &lt;br /&gt;
Re-enter new password: &lt;br /&gt;
Enter LDAP Password: &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;Enter LDAP Password:&amp;lt;/code&amp;gt; use the Directory Manager password there (aka ldap admin). &lt;br /&gt;
&lt;br /&gt;
[https://serverfault.com/questions/731024/freeipa-admin-password-reset Source]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s Encrypt SSL Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Overview ===&lt;br /&gt;
&lt;br /&gt;
My FreeIPA server uses Let&#039;s Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
Here are the instructions for setting up a 3rd party cert for the ldap server &amp;amp; https web interface.&lt;br /&gt;
&lt;br /&gt;
https://www.freeipa.org/page/Using_3rd_part_certificates_for_HTTP/LDAP&lt;br /&gt;
&lt;br /&gt;
To get the CA certs loaded for LE see the section below.&lt;br /&gt;
&lt;br /&gt;
=== Adding Let&#039;s Encrypt CA Authorities ===&lt;br /&gt;
&lt;br /&gt;
I&#039;m using let&#039;s encrypt for the certs for the FreeIPA server. Because of how SSL works, FreeIPA will not accept the LE certs unless it has the CA certs too. This is how you can add a CA cert for LE in Fedora/FreeIPA.&lt;br /&gt;
&lt;br /&gt;
Where it started: I found the basic commands on [https://gist.github.com/lijikun/8b2b3350bce9aed7df3009e76541929c this github writeup link] and modified them.&lt;br /&gt;
&lt;br /&gt;
My Commands to add the R3 CA Authority.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
ipa-cacert-manage install lets-encrypt-r3.pem -n R3 -t C,,&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Found the latest ca cert file here: https://letsencrypt.org/certificates/&lt;br /&gt;
&lt;br /&gt;
Then I was able to use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; to install the cert.&lt;br /&gt;
&lt;br /&gt;
 ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Update&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: Needs even more cert authorities.&lt;br /&gt;
&lt;br /&gt;
Made / borrowed this script do get them all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Fetches LE CA certs for FreeIPA &amp;amp; runs update-ca-certificates.&lt;br /&gt;
# John R., Oct. 2024.&lt;br /&gt;
&lt;br /&gt;
[[ $EUID -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;Run as root!&amp;quot; &amp;amp;&amp;amp; exit 23&lt;br /&gt;
&lt;br /&gt;
set -x&lt;br /&gt;
if ! [[ -d /usr/local/share/ca-certificates/extra ]]; then&lt;br /&gt;
    mkdir -p /usr/local/share/ca-certificates/extra&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/isrgrootx1.crt https://letsencrypt.org/certs/isrgrootx1.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/isrg-root-x2.crt https://letsencrypt.org/certs/isrg-root-x2.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-r3.crt https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-e1.crt https://letsencrypt.org/certs/lets-encrypt-e1.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-r4.crt https://letsencrypt.org/certs/lets-encrypt-r4.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-e2.crt https://letsencrypt.org/certs/lets-encrypt-e2.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/e5.crt https://letsencrypt.org/certs/2024/e5.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/e6.crt https://letsencrypt.org/certs/2024/e6.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/r10.crt https://letsencrypt.org/certs/2024/r10.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/r11.crt https://letsencrypt.org/certs/2024/r11.pem&lt;br /&gt;
&lt;br /&gt;
update-ca-certificates&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/freeipa/freeipa-letsencrypt/issues/25 Original Source]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BlueSquare23/Misc_Bash_Scripts/blob/master/fetch-ca-certs.sh Modified Version on my Github]&lt;br /&gt;
&lt;br /&gt;
=== Renewing an expired cert ===&lt;br /&gt;
&lt;br /&gt;
If the cert for the FreeIPA server expires you can still use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; tool to renew it, like you normally would. However, there&#039;s a catch. You have prepend your command with the &amp;lt;code&amp;gt;faketime&amp;lt;/code&amp;gt; util and set the date to a time before when the current certificate expired.&lt;br /&gt;
&lt;br /&gt;
 EXPIRED!&lt;br /&gt;
 Not After: Mon, 25 Nov 2024 02:26:25 GMT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo faketime &#039;2024-11-24 08:15:42&#039; ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
Directory Manager password: &lt;br /&gt;
&lt;br /&gt;
Enter private key unlock password: &lt;br /&gt;
&lt;br /&gt;
Please restart ipa services after installing certificate (ipactl restart)&lt;br /&gt;
The ipa-server-certinstall command was successful&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just run &amp;lt;code&amp;gt;sudo ipactl restart&amp;lt;/code&amp;gt; to restart the FreeIPA services.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Encode.php&amp;diff=71</id>
		<title>Encode.php</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Encode.php&amp;diff=71"/>
		<updated>2024-11-28T21:36:30Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Encodes a file as base64 gzip compressed payload file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; line&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$input_file = &#039;info.php&#039;;&lt;br /&gt;
$output_file = &#039;x.php&#039;;&lt;br /&gt;
&lt;br /&gt;
function removePhpTags($content) {&lt;br /&gt;
  $content = preg_replace(&#039;/^&amp;lt;\?php\s*/&#039;, &#039;&#039;, $content);&lt;br /&gt;
  $content = preg_replace(&#039;/\s*\?&amp;gt;$/&#039;, &#039;&#039;, $content);&lt;br /&gt;
  return $content;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$file_content = file_get_contents($input_file);&lt;br /&gt;
$file_content = removePhpTags($file_content);&lt;br /&gt;
&lt;br /&gt;
$encoded = base64_encode(gzcompress($file_content));&lt;br /&gt;
$payload = &amp;quot;&amp;lt;?php eval(gzuncompress(base64_decode(&#039;$encoded&#039;)));?&amp;gt;&amp;quot;;&lt;br /&gt;
file_put_contents($output_file, $payload);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Japh&amp;diff=70</id>
		<title>Japh</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Japh&amp;diff=70"/>
		<updated>2024-11-28T21:35:53Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A perl japh is an obfuscated perl program that prints out the message &amp;lt;code&amp;gt;Just another Perl Hacker&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Just another Perl Programmer&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s my first ever attempt at creating a japh.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;perl&amp;quot; line&amp;gt;&lt;br /&gt;
#!/usr/bin/env perl&lt;br /&gt;
# John&#039;s first japh!&lt;br /&gt;
use MIME::Base64;use Compress::Zlib;$s=&#039;blue23&#039;;$p=&#039;japh&#039;;@k=split &lt;br /&gt;
&#039;&#039;,crypt($p,$s);%h=(&#039;1&#039;=&amp;gt;&#039;CEgt&#039;,&#039;Y&#039;=&amp;gt;&#039;CNk=&#039;,&#039;0&#039;=&amp;gt;&#039;UUjM&#039;,&#039;Q&#039;=&amp;gt;&#039;Ti0C&lt;br /&gt;
&#039;,&#039;w&#039;=&amp;gt;&#039;SEzO&#039;,&#039;l&#039;=&amp;gt;&#039;Ki0u&#039;,&#039;2&#039;=&amp;gt;&#039;SC1S&#039;,&#039;3&#039;=&amp;gt;&#039;yy/J&#039;,&#039;U&#039;=&amp;gt;undef,&#039;7&#039;=&amp;gt;&lt;br /&gt;
undef,&#039;x&#039;=&amp;gt;&#039;ylHw&#039;,&#039;N&#039;=&amp;gt;&#039;AG8p&#039;,&#039;b&#039;=&amp;gt;&#039;eJzz&#039;);$japh;foreach (@k){next &lt;br /&gt;
unless $h{$_};$japh.=$h{$_};};print uncompress(decode_base64($japh&lt;br /&gt;
)).&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When run it output:&lt;br /&gt;
 ./japh.pl&lt;br /&gt;
 Just another Perl Hacker&lt;br /&gt;
&lt;br /&gt;
[https://www.perlmonks.org/?node_id=412464 More info]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Loris.php&amp;diff=69</id>
		<title>Loris.php</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Loris.php&amp;diff=69"/>
		<updated>2024-11-28T21:35:01Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Useful little PHP script for holding a connection open for testing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot; line&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// John testing holding a connection open, will clean up. Although I guess if&lt;br /&gt;
// you&#039;re reading this that was a lie, sorry...&lt;br /&gt;
/* Debug&lt;br /&gt;
*/&lt;br /&gt;
ini_set(&#039;display_errors&#039;,&#039;1&#039;);&lt;br /&gt;
ini_set(&#039;display_startup_errors&#039;,&#039;1&#039;);&lt;br /&gt;
error_reporting (E_ALL);&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Randomness Begin...&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
function random_string($length) {&lt;br /&gt;
    $str = random_bytes($length);&lt;br /&gt;
    $str = base64_encode($str);&lt;br /&gt;
    $str = str_replace([&amp;quot;+&amp;quot;, &amp;quot;/&amp;quot;, &amp;quot;=&amp;quot;], &amp;quot;&amp;quot;, $str);&lt;br /&gt;
    $str = substr($str, 0, $length);&lt;br /&gt;
    return $str;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
while (True) {&lt;br /&gt;
    echo random_string(32) .&amp;quot;\n&amp;lt;br&amp;gt;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=How_to_Setup_a_Python_Virtual_Environment&amp;diff=68</id>
		<title>How to Setup a Python Virtual Environment</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=How_to_Setup_a_Python_Virtual_Environment&amp;diff=68"/>
		<updated>2024-11-28T21:04:24Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h2&amp;gt;What is a Virtual Environment?&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Python, just like any programming language, has modules (aka, extensions, imports, includes, libraries, dependencies). These modules are just pre-written pieces of code, like functions and objects, that you can import into your project and use to extend the functionality and ease of use of the base language. Normally on your own computer you&#039;d install modules globally at a system-wide level. The problem with depending on globally installed modules is that it makes code less portable. For example, if script.py is moved from &#039;system A&#039; to &#039;system B&#039;, then the person doing the move must install both script.py and any dependent modules on &#039;system B.&#039; This can be a problem if you don&#039;t have administrative access to &#039;system B.&#039; Likewise, globally installed modules can cause problems if two pieces of software depend on different versions of the same module. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To help remedy these issues, Python has &amp;lt;b&amp;gt;&amp;lt;u&amp;gt;Virtual Environments&amp;lt;/u&amp;gt;&amp;lt;/b&amp;gt;. Virtual Environments are used to install all of your Python modules inside of a local folder that often lives inside of your project directory and is specific to it. Now, if script.py depends on &amp;lt;i&amp;gt;moduleName&amp;lt;/i&amp;gt; and &#039;system B&#039; lacks or has a different globally installed version of &amp;lt;i&amp;gt;moduleName&amp;lt;/i&amp;gt;, then its no big deal. Along side our project we can just spin up a new python virtual env and install those required modules using a [https://notes.johnlradford.io/index.php?title=How_to_Setup_a_Python_Virtual_Environment#Requirements.txt requirements.txt] file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Setting Up a Python Virtualenv&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h4&amp;gt;1) Initialize a new virtual environment:&amp;lt;/h4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 python3 -m venv venv&lt;br /&gt;
&lt;br /&gt;
That will create a directory called venv, where your locally installed modules will live. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;h4&amp;gt;2) Activate your virtual env:&amp;lt;/h4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 source venv/bin/activate&lt;br /&gt;
&lt;br /&gt;
That will drop you into a modified shell. Now, any modules installed using [https://pypi.org/project/pip/ pip] will automatically be installed into the venv dir.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h4&amp;gt;3) Install a module locally:&amp;lt;/h4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 pip3 install requests&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h4&amp;gt;4) Run some python code with your newly installed module:&amp;lt;/h4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 python3 -c &amp;quot;import requests; print(requests.get(&#039;https://johnlradford.io/&#039;))&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h4&amp;gt;5) Exit your virtual env when you&#039;re done installing modules and testing your code:&amp;lt;/h4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 deactivate&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Extras:&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;* Requirements.txt&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is customary to include a &amp;lt;code&amp;gt;requirements.txt&amp;lt;/code&amp;gt; file in your project directory for use in listing out the modules needed to re-assemble your project. Normally you&#039;d use [https://pip.pypa.io/en/stable/cli/pip_freeze/ pip freeze] to generate a requirements.txt file. But that doesn&#039;t seem to work with python virtual envs. So instead I&#039;ve used &amp;lt;code&amp;gt;pipreqs&amp;lt;/code&amp;gt; to get a requirements.txt file. You can install &amp;lt;code&amp;gt;pipreqs&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;pip3&amp;lt;/code&amp;gt; and then just point the tool at a dir containing a python script. It will look at the import lines from the scripts in that dir and print out a list of the required modules.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
blue@server:$app&amp;gt; pipreqs app/&lt;br /&gt;
INFO: Successfully saved requirements file in app/requirements.txt&lt;br /&gt;
blue@server:$app&amp;gt; cat app/requirements.txt &lt;br /&gt;
Flask==2.0.1&lt;br /&gt;
requests==2.22.0&lt;br /&gt;
beautifulsoup4==4.9.3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h3&amp;gt;* Venv Persistence / Python Sub Shells&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, if you&#039;re testing an app you will need to be inside of the virtual env to have access to the modules the app needs. From my testing, it seems the virtual environment will remain set if you drop down into a python shell and pop back up. Likewise, it seems to remain set if you run python with the -c option like used in the example above. This all seems to be maintained via the &amp;lt;code&amp;gt;VIRTUAL_ENV&amp;lt;/code&amp;gt; shell environment variable (idk just sorta spit balling there). For example,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
(venv) blue@server:$app&amp;gt; python3&lt;br /&gt;
Python 3.8.5 (default, Jan 27 2021, 15:41:15) &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import os&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; os.environ[&#039;VIRTUAL_ENV&#039;]&lt;br /&gt;
&#039;/var/www/html/FlaskApp/venv&#039;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; quit()&lt;br /&gt;
(venv) blue@server:$app&amp;gt; echo $VIRTUAL_ENV&lt;br /&gt;
/var/www/html/FlaskApp/venv&lt;br /&gt;
(venv) blue@server:$app&amp;gt; deactivate&lt;br /&gt;
blue@server:$app&amp;gt; [[ -z $VIRTUAL_ENV ]] &amp;amp;&amp;amp; echo &amp;quot;...nada...&amp;quot;&lt;br /&gt;
...nada...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Python]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=67</id>
		<title>FreeIPA - Identity Management</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=FreeIPA_-_Identity_Management&amp;diff=67"/>
		<updated>2024-11-28T20:59:38Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;== Overview ==  https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png  FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.  == How it Works ==  Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.  Access to hosts on the network are controlled via Host B...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
https://raw.githubusercontent.com/freeipa/freeipa.github.io/main/src/_static/freeipa-logo-small.png&lt;br /&gt;
&lt;br /&gt;
FreeIPA is an identity management &amp;amp; single sign on solution for Linux / Unix Networks. Its somewhat comparable to active directory in the Windows world.&lt;br /&gt;
&lt;br /&gt;
== How it Works ==&lt;br /&gt;
&lt;br /&gt;
Under the hood FreeIPA is really just wraps up a Kerberos KDC/KTG Server with an LDAP backend and a nice pretty web interface.&lt;br /&gt;
&lt;br /&gt;
Access to hosts on the network are controlled via Host Based Access (HBA) Control Rules, which say what users are allowed access (via ssh) to what hosts.&lt;br /&gt;
&lt;br /&gt;
== Restarting All IPA Services ==&lt;br /&gt;
&lt;br /&gt;
You can use the command below to restart all FreeIPA services.&lt;br /&gt;
&lt;br /&gt;
 sudo ipactl restart&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a systemd daemon for the main ipa service.&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl restart ipa&lt;br /&gt;
&lt;br /&gt;
== Resetting The Admin Password ==&lt;br /&gt;
&lt;br /&gt;
I&#039;ve had to do this once when restoring from a backup after changing the admin pass and loosing the old one. So I might have to do it again some day.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@freeipa:~# export LDAPTLS_CACERT=/etc/ipa/ca.crt&lt;br /&gt;
root@freeipa:~# ldappasswd -ZZ -D &#039;cn=directory manager&#039; -W -S uid=admin,cn=users,cn=accounts,dc=yourdomain,dc=net -H ldap://freeipa.yourdomain.net&lt;br /&gt;
New password: &lt;br /&gt;
Re-enter new password: &lt;br /&gt;
Enter LDAP Password: &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;Enter LDAP Password:&amp;lt;/code&amp;gt; use the Directory Manager password there (aka ldap admin). &lt;br /&gt;
&lt;br /&gt;
[https://serverfault.com/questions/731024/freeipa-admin-password-reset Source]&lt;br /&gt;
&lt;br /&gt;
== Let&#039;s Encrypt SSL Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Basic Overview ===&lt;br /&gt;
&lt;br /&gt;
My FreeIPA server uses Let&#039;s Encrypt certificates.&lt;br /&gt;
&lt;br /&gt;
Here are the instructions for setting up a 3rd party cert for the ldap server &amp;amp; https web interface.&lt;br /&gt;
&lt;br /&gt;
https://www.freeipa.org/page/Using_3rd_part_certificates_for_HTTP/LDAP&lt;br /&gt;
&lt;br /&gt;
To get the CA certs loaded for LE see the section below.&lt;br /&gt;
&lt;br /&gt;
=== Adding Let&#039;s Encrypt CA Authorities ===&lt;br /&gt;
&lt;br /&gt;
I&#039;m using let&#039;s encrypt for the certs for the FreeIPA server. Because of how SSL works, FreeIPA will not accept the LE certs unless it has the CA certs too. This is how you can add a CA cert for LE in Fedora/FreeIPA.&lt;br /&gt;
&lt;br /&gt;
Where it started: I found the basic commands on [https://gist.github.com/lijikun/8b2b3350bce9aed7df3009e76541929c this github writeup link] and modified them.&lt;br /&gt;
&lt;br /&gt;
My Commands to add the R3 CA Authority.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wget https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
ipa-cacert-manage install lets-encrypt-r3.pem -n R3 -t C,,&lt;br /&gt;
ipa-certupdate&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Found the latest ca cert file here: https://letsencrypt.org/certificates/&lt;br /&gt;
&lt;br /&gt;
Then I was able to use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; to install the cert.&lt;br /&gt;
&lt;br /&gt;
 ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Update&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: Needs even more cert authorities.&lt;br /&gt;
&lt;br /&gt;
Made / borrowed this script do get them all.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Fetches LE CA certs for FreeIPA &amp;amp; runs update-ca-certificates.&lt;br /&gt;
# John R., Oct. 2024.&lt;br /&gt;
&lt;br /&gt;
[[ $EUID -ne 0 ]] &amp;amp;&amp;amp; echo &amp;quot;Run as root!&amp;quot; &amp;amp;&amp;amp; exit 23&lt;br /&gt;
&lt;br /&gt;
set -x&lt;br /&gt;
if ! [[ -d /usr/local/share/ca-certificates/extra ]]; then&lt;br /&gt;
    mkdir -p /usr/local/share/ca-certificates/extra&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/isrgrootx1.crt https://letsencrypt.org/certs/isrgrootx1.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/isrg-root-x2.crt https://letsencrypt.org/certs/isrg-root-x2.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-r3.crt https://letsencrypt.org/certs/lets-encrypt-r3.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-e1.crt https://letsencrypt.org/certs/lets-encrypt-e1.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-r4.crt https://letsencrypt.org/certs/lets-encrypt-r4.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/lets-encrypt-e2.crt https://letsencrypt.org/certs/lets-encrypt-e2.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/e5.crt https://letsencrypt.org/certs/2024/e5.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/e6.crt https://letsencrypt.org/certs/2024/e6.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/r10.crt https://letsencrypt.org/certs/2024/r10.pem&lt;br /&gt;
wget -O /usr/local/share/ca-certificates/extra/r11.crt https://letsencrypt.org/certs/2024/r11.pem&lt;br /&gt;
&lt;br /&gt;
update-ca-certificates&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://github.com/freeipa/freeipa-letsencrypt/issues/25 Original Source]&lt;br /&gt;
&lt;br /&gt;
[https://github.com/BlueSquare23/Misc_Bash_Scripts/blob/master/fetch-ca-certs.sh Modified Version on my Github]&lt;br /&gt;
&lt;br /&gt;
=== Renewing an expired cert ===&lt;br /&gt;
&lt;br /&gt;
If the cert for the FreeIPA server expires you can still use the &amp;lt;code&amp;gt;ipa-server-certinstall&amp;lt;/code&amp;gt; tool to renew it, like you normally would. However, there&#039;s a catch. You have prepend your command with the &amp;lt;code&amp;gt;faketime&amp;lt;/code&amp;gt; util and set the date to a time before when the current certificate expired.&lt;br /&gt;
&lt;br /&gt;
 EXPIRED!&lt;br /&gt;
 Not After: Mon, 25 Nov 2024 02:26:25 GMT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo faketime &#039;2024-11-24 08:15:42&#039; ipa-server-certinstall -w -d &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/fullchain.pem&amp;quot; &amp;quot;/etc/letsencrypt/live/freeipa.yourdomain.net/privkey.pem&amp;quot;&lt;br /&gt;
Directory Manager password: &lt;br /&gt;
&lt;br /&gt;
Enter private key unlock password: &lt;br /&gt;
&lt;br /&gt;
Please restart ipa services after installing certificate (ipactl restart)&lt;br /&gt;
The ipa-server-certinstall command was successful&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then just run &amp;lt;code&amp;gt;sudo ipactl restart&amp;lt;/code&amp;gt; to restart the FreeIPA services.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=GPG_Encryption&amp;diff=66</id>
		<title>GPG Encryption</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=GPG_Encryption&amp;diff=66"/>
		<updated>2024-09-23T16:56:22Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= GPG - GNU Privacy Guard =&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
&lt;br /&gt;
GPG is an alternative implementation of the OpenPGP standard. GPG/PGP uses [[Encoding_vs_Encryption_vs_Hashing#Symmetric_vs_Asymmetric_Encryption|asymmetric encryption]] to generate a public / private key pair. With asymmetric encryption, any data encrypted by the public key can only be decrypted by the private key and vice versa.&lt;br /&gt;
&lt;br /&gt;
The intention is to make your public key known and freely available while keeping your private key secret. Other’s can then use your public key to encrypt some data and send it to you, knowing that only you can decrypt it with your private key.&lt;br /&gt;
&lt;br /&gt;
== Common Commands ==&lt;br /&gt;
&lt;br /&gt;
Note: We&#039;ll be using email@example.com as a stand in for a key&#039;s identifier. The GPG tool will let you use a few different things in place of email@example.com to work as a key&#039;s identifier.&lt;br /&gt;
&lt;br /&gt;
To create a new key pair run the command below and follow the dialogue options.&lt;br /&gt;
&lt;br /&gt;
 gpg --full-generate-key&lt;br /&gt;
&lt;br /&gt;
After generating your keys you can list them with the command below.&lt;br /&gt;
&lt;br /&gt;
 gpg --list-keys&lt;br /&gt;
&lt;br /&gt;
You can list the secret keys you have with the command below.&lt;br /&gt;
&lt;br /&gt;
 gpg --list-secret-keys&lt;br /&gt;
&lt;br /&gt;
Immediately after creating a new keypair you’ll want to sign your own key.&lt;br /&gt;
&lt;br /&gt;
 gpg --sign-key email@example.com&lt;br /&gt;
&lt;br /&gt;
From there you’re ready to export your public key and give it to others.&lt;br /&gt;
&lt;br /&gt;
 gpg --output ~/gpg_key.pub --armor --export email@example.com&lt;br /&gt;
&lt;br /&gt;
Once your friend has your public gpg key they can import it using the command below.&lt;br /&gt;
&lt;br /&gt;
 gpg --import ~/gpg_key.pub&lt;br /&gt;
&lt;br /&gt;
Then to encrypt something with your public key your friend can run the below with your public key.&lt;br /&gt;
&lt;br /&gt;
 gpg --encrypt --sign --armor -r email@example.com file.txt&lt;br /&gt;
&lt;br /&gt;
That will generate a file.txt.gpg which is the encrypted copy of the message.&lt;br /&gt;
&lt;br /&gt;
Once your friend sends you the encrypted file.txt.gpg back you can verify its authenticity by running the commmand below.&lt;br /&gt;
&lt;br /&gt;
 gpg --always-trust --verify file.txt.gpg&lt;br /&gt;
&lt;br /&gt;
Finally you can decrypt it with the below command.&lt;br /&gt;
&lt;br /&gt;
 gpg --decrypt file.txt.gpg&lt;br /&gt;
&lt;br /&gt;
Here are some additional commands.&lt;br /&gt;
&lt;br /&gt;
To delete someone else&#039;s public key from your keychain.&lt;br /&gt;
&lt;br /&gt;
 gpg --delete-key email@example.com&lt;br /&gt;
&lt;br /&gt;
To delete your own secret key.&lt;br /&gt;
&lt;br /&gt;
 gpg --delete-secret-key email@example.com &amp;amp;&amp;amp; gpg --delete-key email@example.com&lt;br /&gt;
&lt;br /&gt;
To see how much GPG clout a particular key has check the number of signatures.&lt;br /&gt;
&lt;br /&gt;
 gpg --list-sig email@example.com&lt;br /&gt;
&lt;br /&gt;
To list the longform keyid format ([https://phar.io/howto/uploading-public-keys.html#:~:text=Alternate%20way%20to%20submit%20your%20public%20key%20to%20the%20key%20servers%20using%20the%20CLI needed to get sub fingerprint for later upload]).&lt;br /&gt;
&lt;br /&gt;
 gpg --keyid-format LONG --list-keys email@example.com&lt;br /&gt;
&lt;br /&gt;
To send a key to the three major key stores out there.&lt;br /&gt;
&lt;br /&gt;
 gpg --send-keys 156DF784C8EACD80    # OpenPGP&lt;br /&gt;
 gpg --keyserver keys.openpgp.org --send-keys 156DF784C8EACD80    # OpenGPG&lt;br /&gt;
 gpg --keyserver keyserver.ubuntu.com --send-keys 156DF784C8EACD80    # Ubuntu&lt;br /&gt;
&lt;br /&gt;
Search a keystore for a persons key.&lt;br /&gt;
&lt;br /&gt;
 gpg --keyserver keys.openpgp.org --search-keys email@example.com&lt;br /&gt;
&lt;br /&gt;
== Signing &amp;amp;amp; Encrypting ==&lt;br /&gt;
&lt;br /&gt;
GPG offers the ability to sign data and to encrypt data. Message signing ensures data integrity (aka the message has not been changed) and message authenticity (aka the message came from where it says it came from). Where as encryption ensure confidentiality (aka that the data cannot be read in transit).&lt;br /&gt;
&lt;br /&gt;
In reality, signing is just encrypting a message using the private key. Then it can only be decrypted by the corresponding public key. Anyone can with the public key can decrypt and read a signed message. They know since they used the public key to decrypt it that it must have been encrypted (aka signed) with the private key and therefore must have come from the private key holder.&lt;br /&gt;
&lt;br /&gt;
Signing and encryption are not mutually exclusive. With GPG its possible for data to be, encrypted and signed; encrypted and not signed; and signed but not encrypted.&lt;br /&gt;
&lt;br /&gt;
The most secure method is to first encrypt a message with the recipient’s public key and then sign the message using your private key before sending it. That way on the receiving side anyone can verify that the message came from you because it can only be decrypted with your public key. Likewise, they can know that the message has not been altered in transit because again the signed file could only have been created by your private key.&lt;br /&gt;
&lt;br /&gt;
The signature on a message becomes invalid if the message is altered, even if the message is sent in plain text. If someone changed the message the signature file would also need changed and the only person who can change the signature file is the private key holder.&lt;br /&gt;
&lt;br /&gt;
Finally once the recipient receives the message and verifies its authenticity they can then decrypt it using their private key.&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
https://gist.github.com/F21/b0e8c62c49dfab267ff1d0c6af39ab84&lt;br /&gt;
&lt;br /&gt;
https://www.digitalocean.com/community/tutorials/how-to-use-gpg-to-encrypt-and-sign-messages&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=65</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=65"/>
		<updated>2024-07-26T19:32:46Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is a complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate this further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, we&#039;re going to be compiling the first two from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build these packages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;NOTE&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; built and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=64</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=64"/>
		<updated>2024-07-26T19:31:05Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is a complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate this further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, we&#039;re going to be compiling the first two from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build these packages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&amp;lt;i&amp;gt;NOTE&amp;lt;/i&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/span&amp;gt;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; build and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=63</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=63"/>
		<updated>2024-07-26T19:29:55Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is a complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate this further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, we&#039;re going to be compiling the first two from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build these packages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; build and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=62</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=62"/>
		<updated>2024-07-26T19:29:02Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is a complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate this further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, we&#039;re going to be compiling the first two from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build this package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; build and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=61</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=61"/>
		<updated>2024-07-26T19:28:23Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is a complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate this further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, the first two have to be compiled from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build this package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; build and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=60</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=60"/>
		<updated>2024-07-26T19:27:08Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is a complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate this further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, these have to be compiled from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build this package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; build and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=59</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=59"/>
		<updated>2024-07-26T19:25:51Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is a complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, these have to be compiled from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build this package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; build and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=58</id>
		<title>Setting Up Libmodsecurity3, Nginx Connector, &amp; OWASP Ruleset on Nginx</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Setting_Up_Libmodsecurity3,_Nginx_Connector,_%26_OWASP_Ruleset_on_Nginx&amp;diff=58"/>
		<updated>2024-07-26T19:22:20Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =  Logos  == Background Info ==  Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].  This transfer of stewardship means continued development of [https://github.c...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Setting Up Libmodsecurity3, Nginx Connector, &amp;amp;amp; OWASP Ruleset on Nginx =&lt;br /&gt;
&lt;br /&gt;
[[File:logos.png|thumb|none|alt=Logos|Logos]]&lt;br /&gt;
&lt;br /&gt;
== Background Info ==&lt;br /&gt;
&lt;br /&gt;
Okay so tldr the modsecurity project recently back in January of 2024 switched hands from Trustwave SpiderLabs to the OWASP Foundation. [https://coreruleset.org/20240115/welcome-the-newest-addition-to-the-owasp-family-modsecurity/ More info here].&lt;br /&gt;
&lt;br /&gt;
This transfer of stewardship means continued development of [https://github.com/owasp-modsecurity/ModSecurity libmodsecurity3], is now under OWASP’s control. The new &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; is complete rewrite, allowing them to make it platform independent (not dependant on Apache). Tldr, [https://github.com/owasp-modsecurity/ModSecurity?tab=readme-ov-file#it-is-no-longer-just-a-module it is no longer just a module], it is its own library now, with the “Connectors” broken out into their own separate github repos.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity-nginx Nginx ModSecurity Connector]&lt;br /&gt;
&lt;br /&gt;
Another thing, even though Nginx does have a connector and can use libmodsecurity3, the version of the package in apt its several years old already (default version in apt is v3.0.6 from 2021) and lack support for the newest features.&lt;br /&gt;
&lt;br /&gt;
All of the guides I’ve found and even [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-%28v3.x%29#user-content-Installation_for_NGINX the official install docs] say to just build the latest releases of the lib and connector from source. Trust me, its really not that hard.&lt;br /&gt;
&lt;br /&gt;
== Nginx ModSecurity ==&lt;br /&gt;
&lt;br /&gt;
I’m installing this on a burner VM running Ubuntu 22.04 and Nginx 1.18.0, just to learn and document the process before trying to integrate further into my own systems.&lt;br /&gt;
&lt;br /&gt;
[[File:fastfetch.png|thumb|none|alt=Fastfetch Img|Fastfetch Img]]&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The server and Nginx are already setup stock with one Server Block (aka vhost) defined. I’m using the stock version of Nginx from apt.&lt;br /&gt;
&lt;br /&gt;
What all needs setup?&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v3.0.12 libmodsecurity3 - v3.0.12]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity-nginx/releases/tag/v1.0.3 ModSecurity Nginx Connector - v1.0.3]&lt;br /&gt;
* [https://owasp.org/www-project-modsecurity-core-rule-set/ OWASP ModSec CSR - v4.0.0]&lt;br /&gt;
&lt;br /&gt;
As mentioned previously, these have to be compiled from source.&lt;br /&gt;
&lt;br /&gt;
Mostly following their [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-2210 official docs]. I know that’s for 22.10 but I they don’t have one for 22.04 yet so assuming those are mostly the same apt reqs. Except our version of nginx needs to use libpcre3.&lt;br /&gt;
&lt;br /&gt;
=== Apt Requirements ===&lt;br /&gt;
&lt;br /&gt;
There are some requirements to build this package.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt-get install git g++ apt-utils autoconf automake build-essential libcurl4-openssl-dev libgeoip-dev liblmdb-dev libtool libxml2-dev libyajl-dev pkgconf zlib1g-dev libpcre3 libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Libmodsecurity v3.0.12 from Source ===&lt;br /&gt;
&lt;br /&gt;
Pretty straight forward, just clone the repo (master is v3.0.12) then update the git submodules and build with normal make cmds.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
git clone https://github.com/owasp-modsecurity/ModSecurity&lt;br /&gt;
cd ModSecurity/&lt;br /&gt;
git submodule init&lt;br /&gt;
git submodule update&lt;br /&gt;
sh build.sh&lt;br /&gt;
./configure --with-pcre&lt;br /&gt;
make&lt;br /&gt;
make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Building Nginx Connector Module v1.0.3 ===&lt;br /&gt;
&lt;br /&gt;
After installing the library you can build the connector.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: The connector module has to be compiled against the source code version of Nginx you have installed.&lt;br /&gt;
&lt;br /&gt;
Check Nginx version and build flags:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;root@server:/opt# nginx -V&lt;br /&gt;
nginx version: nginx/1.18.0 (Ubuntu)&lt;br /&gt;
built with OpenSSL 3.0.2 15 Mar 2022&lt;br /&gt;
TLS SNI support enabled&lt;br /&gt;
configure arguments: --with-cc-opt=&#039;-g -O2 -ffile-prefix-map=/build/nginx-zctdR4/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2&#039; --with-ld-opt=&#039;-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC&#039; --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=/build/nginx-zctdR4/nginx-1.18.0/debian/modules/http-geoip2 --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module&amp;lt;/pre&amp;gt;&lt;br /&gt;
To quote [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ the guide I’m following].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;We need to compile Nginx with ModSecurity module. We will not compile/install Nginx itself but compile the Nginx module only. For this, make sure that your Nginx package is compiled with “–with-compat” flag. The –with-compat flag will make the module binary-compatible with your existing Nginx binary.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
First clone the source for the version of nginx you’re running. In our case, &amp;lt;code&amp;gt;nginx/1.18.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget http://nginx.org/download/nginx-1.18.0.tar.gz&lt;br /&gt;
tar -xzf nginx-1.18.0.tar.gz&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then clone the latest connector module repo. After that build the modules for Nginx and copy the .so file into &amp;lt;code&amp;gt;/usr/share/nginx/modules/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;git clone https://github.com/owasp-modsecurity/ModSecurity-nginx&lt;br /&gt;
cd nginx-1.18.0&lt;br /&gt;
./configure --add-dynamic-module=/opt/ModSecurity-nginx --with-compat&lt;br /&gt;
make modules&lt;br /&gt;
cp objs/ngx_http_modsecurity_module.so /usr/share/nginx/modules/&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Configuring Nginx ===&lt;br /&gt;
&lt;br /&gt;
Cool, so now we’ve got &amp;lt;code&amp;gt;libmodsecurity3&amp;lt;/code&amp;gt; build and installed, we’ve got the nginx connector module built and installed, and we just have to setup Nginx to work with them.&lt;br /&gt;
&lt;br /&gt;
==== Installing OWASP CSR v4 ====&lt;br /&gt;
&lt;br /&gt;
First we’ll install core ruleset version 4. These instructions are basically exactly the same as for Apache, just pulling in the ruleset files really.&lt;br /&gt;
&lt;br /&gt;
To install the core ruleset version v4.0.0 (latest stable) you can pull them from github.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/archive/refs/tags/v4.0.0.tar.gz&lt;br /&gt;
wget https://github.com/coreruleset/coreruleset/releases/download/v4.0.0/coreruleset-4.0.0.tar.gz.asc&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you can add their pgp key and verify the signature with it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gpg --keyserver keys.openpgp.org --recv 0x38EEACA1AB8A6E72&lt;br /&gt;
gpg: /root/.gnupg/trustdb.gpg: trustdb created&lt;br /&gt;
gpg: key 38EEACA1AB8A6E72: public key &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; imported&lt;br /&gt;
gpg: Total number processed: 1&lt;br /&gt;
gpg:               imported: 1&lt;br /&gt;
&lt;br /&gt;
# gpg --verify coreruleset-4.0.0.tar.gz.asc v4.0.0.tar.gz&lt;br /&gt;
gpg: Signature made Wed 14 Feb 2024 05:48:48 PM UTC&lt;br /&gt;
gpg:                using RSA key 36006F0E0BA167832158821138EEACA1AB8A6E72&lt;br /&gt;
gpg:                issuer &amp;amp;quot;security@coreruleset.org&amp;amp;quot;&lt;br /&gt;
gpg: Good signature from &amp;amp;quot;OWASP Core Rule Set &amp;amp;lt;security@coreruleset.org&amp;amp;gt;&amp;amp;quot; [unknown]&lt;br /&gt;
gpg: WARNING: This key is not certified with a trusted signature!&lt;br /&gt;
gpg:          There is no indication that the signature belongs to the owner.&lt;br /&gt;
Primary key fingerprint: 3600 6F0E 0BA1 6783 2158  8211 38EE ACA1 AB8A 6E72&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you’ve verified the fingerprint is legit you’re all good to extract the ruleset.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /opt/crs4&lt;br /&gt;
tar -xzvf v4.0.0.tar.gz --strip-components 1 -C /opt/crs4&amp;lt;/pre&amp;gt;&lt;br /&gt;
Lastly, copy the example crs-conf file into place.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /opt/crs4&lt;br /&gt;
mv crs-setup.conf.example crs-setup.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
==== Setting Up Module &amp;amp;amp; Nginx Conf ====&lt;br /&gt;
&lt;br /&gt;
Add the &amp;lt;code&amp;gt;load_module&amp;lt;/code&amp;gt; line to &amp;lt;code&amp;gt;50-mod-http-modsecurity.conf&amp;lt;/code&amp;gt; and then create a symlink to enable the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;load_module modules/ngx_http_modsecurity_module.so;&#039; &amp;amp;gt; /usr/share/nginx/modules-available/mod-http-modsecurity.conf&lt;br /&gt;
ln -s /usr/share/nginx/modules-available/mod-http-modsecurity.conf /etc/nginx/modules-enabled/50-mod-http-modsecurity.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then copy the recommended mod sec conf into place. There’s also a &amp;lt;code&amp;gt;unicode.mapping&amp;lt;/code&amp;gt; that should be copied over too.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;mkdir /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity-nginx/.github/nginx/modsecurity.conf /etc/nginx/modsec/&lt;br /&gt;
cp /opt/ModSecurity/unicode.mapping /etc/nginx/modsec&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now we can create our main ModSec conf: &amp;lt;code&amp;gt;/etc/nginx/modsec/main.conf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Add these lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Include /etc/nginx/modsec/modsecurity.conf&lt;br /&gt;
Include /opt/crs4/crs-setup.conf&lt;br /&gt;
Include /opt/crs4/rules/*.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, in our main site’s server block we can enable mod security for our site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;vim /etc/nginx/sites-available/example.com&amp;lt;/pre&amp;gt;&lt;br /&gt;
Add these contents to the server block.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;modsecurity on;&lt;br /&gt;
modsecurity_rules_file /etc/nginx/modsec/main.conf;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, restart Nginx and enjoy the protections of libmodsecurity3 + the OWASP ruleset!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can test your new mod security setup is working correctly by visiting &amp;lt;code&amp;gt;https://yourdomain.com/?test=/etc/passwd&amp;lt;/code&amp;gt; in a browser. If everything is setup correctly you should now be greeted with a 403 forbidden.&lt;br /&gt;
&lt;br /&gt;
[[File:testing_modsec.png|thumb|none|alt=testing mod security|testing mod security]]&lt;br /&gt;
&lt;br /&gt;
=== Sources ===&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v3.x)#user-content-Installation_for_NGINX Official ModSecurity Lib Install Docs]&lt;br /&gt;
* [https://github.com/owasp-modsecurity/ModSecurity/wiki/Compilation-recipes-for-v3.x#ubuntu-1804 Official Compilation recipes for libmodsecurity v3.x]&lt;br /&gt;
* [https://www.webhi.com/how-to/how-to-install-modsecurity-in-nginx-on-ubuntu-18-04-20-4-22-04-debian/ Dev Blog on Compiling ModSecurity lib &amp;amp;amp; connector module]&lt;br /&gt;
* [https://nagekar.com/2022/07/setting-modsecurity-core-rule-set.html Dev Blog on Setting Up OWASP CRS on Nginx]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=File:Testing_modsec.png&amp;diff=57</id>
		<title>File:Testing modsec.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=File:Testing_modsec.png&amp;diff=57"/>
		<updated>2024-07-26T19:22:09Z</updated>

		<summary type="html">&lt;p&gt;Admin: testing mod security is configured properly and working by entering the query string ?test=/etc/passwd, should return a 403 if working!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
testing mod security is configured properly and working by entering the query string ?test=/etc/passwd, should return a 403 if working!&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=File:Fastfetch.png&amp;diff=56</id>
		<title>File:Fastfetch.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=File:Fastfetch.png&amp;diff=56"/>
		<updated>2024-07-26T19:20:39Z</updated>

		<summary type="html">&lt;p&gt;Admin: Image of neofetch (aka now fastfetch) out for burner vm for mod sec on nginx post. Might be useful to someone to see kernel version or something :shrug:&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Image of neofetch (aka now fastfetch) out for burner vm for mod sec on nginx post. Might be useful to someone to see kernel version or something :shrug:&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=File:Logos.png&amp;diff=55</id>
		<title>File:Logos.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=File:Logos.png&amp;diff=55"/>
		<updated>2024-07-26T19:19:33Z</updated>

		<summary type="html">&lt;p&gt;Admin: Image of mod security, OWASP, and Nginx Logos all together.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Image of mod security, OWASP, and Nginx Logos all together.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=MediaWiki:Citizen-footer-tagline&amp;diff=54</id>
		<title>MediaWiki:Citizen-footer-tagline</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=MediaWiki:Citizen-footer-tagline&amp;diff=54"/>
		<updated>2024-07-26T19:16:25Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot; Don&amp;#039;t forget your towel! &amp;lt;!-- MediaWiki:Citizen-footer-tagline --&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Don&#039;t forget your towel!&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
[[MediaWiki:Citizen-footer-tagline]]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=MediaWiki:Citizen-footer-desc&amp;diff=53</id>
		<title>MediaWiki:Citizen-footer-desc</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=MediaWiki:Citizen-footer-desc&amp;diff=53"/>
		<updated>2024-07-26T19:14:42Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;A place for lost lovers... &amp;lt;!-- MediaWiki:Citizen-footer-desc --&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A place for lost lovers...&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
[[MediaWiki:Citizen-footer-desc]]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=52</id>
		<title>Apache2 Mod Security v2.9.7 Compilation Instructions</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=52"/>
		<updated>2024-07-17T21:45:10Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
Going to be compiling &amp;lt;code&amp;gt;mod_security2&amp;lt;/code&amp;gt; (v2.9.7) for Apache2 on Ubuntu 22.04. This module is pretty straight forward to compile. However, there are some dependencies.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt install apache2-dev gcc libxml2 libxml2-dev libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have &amp;lt;code&amp;gt;libapache2-mod-security2&amp;lt;/code&amp;gt; installed via apt then disable and uninstall it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo a2dismod security2&lt;br /&gt;
sudo apt purge libapache2-mod-security2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then fetch the latest tarball from their github releases page and compile it using normal make cmds. Finally, make sure to enable the module and restart Apache.&lt;br /&gt;
&lt;br /&gt;
https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v2.9.7&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/owasp-modsecurity/ModSecurity/releases/download/v2.9.7/modsecurity-2.9.7.tar.gz&lt;br /&gt;
tar -xzvf modsecurity-2.9.7.tar.gz&lt;br /&gt;
cd modsecurity-2.9.7&lt;br /&gt;
./configure --with-apxs=/usr/bin/apxs&lt;br /&gt;
make&lt;br /&gt;
make install&lt;br /&gt;
echo &#039;LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so&#039; &amp;amp;gt; /etc/apache2/mods-available/security2.load&lt;br /&gt;
a2enmod security2&lt;br /&gt;
systemctl restart apache2&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you should be able to see mod security enabled and working in the Apache error logs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[Wed Jul 17 19:25:21.038359 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity for Apache/2.9.7 (http://www.modsecurity.org/) configured.&lt;br /&gt;
[Wed Jul 17 19:25:21.038434 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: APR compiled version=&amp;amp;quot;1.7.0&amp;amp;quot;; loaded version=&amp;amp;quot;1.7.0&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038447 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: PCRE compiled version=&amp;amp;quot;8.39 &amp;amp;quot;; loaded version=&amp;amp;quot;8.39 2016-06-14&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038449 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: LIBXML compiled version=&amp;amp;quot;2.9.13&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038549 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: StatusEngine call: &amp;amp;quot;2.9.7,Apache/2.4.52 (Ubuntu),1.7.0/1.7.0,8.39/8.39 2016-06-14,(null),2.9.13,e013612419474187e43b03a4f546e0736dc12934&amp;amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Additional Resources ==&lt;br /&gt;
&lt;br /&gt;
Please see their official handbook for more details on compiling this module.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#installation-steps Reference-Manual-v2.x]&lt;br /&gt;
&lt;br /&gt;
Also be sure to run &amp;lt;code&amp;gt;./configure --help&amp;lt;/code&amp;gt; for more information about how to compile this for your system.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=51</id>
		<title>Apache2 Mod Security v2.9.7 Compilation Instructions</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=51"/>
		<updated>2024-07-17T21:43:30Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
Going to be compiling &amp;lt;code&amp;gt;mod_security2&amp;lt;/code&amp;gt; (v2.9.7) for Apache2 on Ubuntu 22.04. This module is pretty straight forward to compile. However, there are some dependencies.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt install apache2-dev gcc libxml2 libxml2-dev libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you already have &amp;lt;code&amp;gt;libapache2-mod-security2&amp;lt;/code&amp;gt; installed via apt then disable and uninstall it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo a2dismod security2&lt;br /&gt;
sudo apt purge libapache2-mod-security2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then fetch the latest tarball from their github releases page. Then compile it using normal make cmds.&lt;br /&gt;
&lt;br /&gt;
https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v2.9.7&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/owasp-modsecurity/ModSecurity/releases/download/v2.9.7/modsecurity-2.9.7.tar.gz&lt;br /&gt;
tar -xzvf modsecurity-2.9.7.tar.gz&lt;br /&gt;
cd modsecurity-2.9.7&lt;br /&gt;
./configure --with-apxs=/usr/bin/apxs&lt;br /&gt;
make&lt;br /&gt;
make install&lt;br /&gt;
echo &#039;LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so&#039; &amp;amp;gt; /etc/apache2/mods-available/security2.load&lt;br /&gt;
a2enmod security2&lt;br /&gt;
systemctl restart apache2&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you should be able to see mod security enabled and working in the Apache error logs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[Wed Jul 17 19:25:21.038359 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity for Apache/2.9.7 (http://www.modsecurity.org/) configured.&lt;br /&gt;
[Wed Jul 17 19:25:21.038434 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: APR compiled version=&amp;amp;quot;1.7.0&amp;amp;quot;; loaded version=&amp;amp;quot;1.7.0&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038447 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: PCRE compiled version=&amp;amp;quot;8.39 &amp;amp;quot;; loaded version=&amp;amp;quot;8.39 2016-06-14&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038449 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: LIBXML compiled version=&amp;amp;quot;2.9.13&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038549 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: StatusEngine call: &amp;amp;quot;2.9.7,Apache/2.4.52 (Ubuntu),1.7.0/1.7.0,8.39/8.39 2016-06-14,(null),2.9.13,e013612419474187e43b03a4f546e0736dc12934&amp;amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Additional Resources ==&lt;br /&gt;
&lt;br /&gt;
Please see their official handbook for more details on compiling this module.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#installation-steps Reference-Manual-v2.x]&lt;br /&gt;
&lt;br /&gt;
Also be sure to run &amp;lt;code&amp;gt;./configure --help&amp;lt;/code&amp;gt; for more information about how to compile this for your system.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=50</id>
		<title>Apache2 Mod Security v2.9.7 Compilation Instructions</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=50"/>
		<updated>2024-07-17T19:55:08Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
Going to be compiling &amp;lt;code&amp;gt;mod_security2&amp;lt;/code&amp;gt; (v2.9.7) for Apache2 on Ubuntu 22.04. This module is pretty straight forward to compile. However, there are some dependencies.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt install apache2-dev gcc libxml2 libxml2-dev libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
Fetch the tarball from their github releases page. Then compile it using normal make cmds.&lt;br /&gt;
&lt;br /&gt;
https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v2.9.7&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/owasp-modsecurity/ModSecurity/releases/download/v2.9.7/modsecurity-2.9.7.tar.gz&lt;br /&gt;
tar -xzvf modsecurity-2.9.7.tar.gz&lt;br /&gt;
cd modsecurity-2.9.7&lt;br /&gt;
./configure --with-apxs=/usr/bin/apxs&lt;br /&gt;
make&lt;br /&gt;
make install&lt;br /&gt;
echo &#039;LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so&#039; &amp;amp;gt; /etc/apache2/mods-available/security2.load&lt;br /&gt;
a2enmod security2&lt;br /&gt;
systemctl restart apache2&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you should be able to see mod security enabled and working in the Apache error logs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[Wed Jul 17 19:25:21.038359 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity for Apache/2.9.7 (http://www.modsecurity.org/) configured.&lt;br /&gt;
[Wed Jul 17 19:25:21.038434 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: APR compiled version=&amp;amp;quot;1.7.0&amp;amp;quot;; loaded version=&amp;amp;quot;1.7.0&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038447 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: PCRE compiled version=&amp;amp;quot;8.39 &amp;amp;quot;; loaded version=&amp;amp;quot;8.39 2016-06-14&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038449 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: LIBXML compiled version=&amp;amp;quot;2.9.13&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038549 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: StatusEngine call: &amp;amp;quot;2.9.7,Apache/2.4.52 (Ubuntu),1.7.0/1.7.0,8.39/8.39 2016-06-14,(null),2.9.13,e013612419474187e43b03a4f546e0736dc12934&amp;amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Additional Resources ==&lt;br /&gt;
&lt;br /&gt;
Please see their official handbook for more details on compiling this module.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#installation-steps Reference-Manual-v2.x]&lt;br /&gt;
&lt;br /&gt;
Also be sure to run &amp;lt;code&amp;gt;./configure --help&amp;lt;/code&amp;gt; for more information about how to compile this for your system.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=49</id>
		<title>Apache2 Mod Security v2.9.7 Compilation Instructions</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Apache2_Mod_Security_v2.9.7_Compilation_Instructions&amp;diff=49"/>
		<updated>2024-07-17T19:52:37Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;== Overview ==  Going to be compiling &amp;lt;code&amp;gt;mod_security2&amp;lt;/code&amp;gt; (v2.9.7) for Apache2 on Ubuntu 22.04. This module is pretty straight forward to compile. However, there are some dependencies.  &amp;lt;pre&amp;gt;sudo apt install apache2-dev gcc libxml2 libxml2-dev libpcre3-dev&amp;lt;/pre&amp;gt; Fetch the tarball from their github releases page.  https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v2.9.7  &amp;lt;pre&amp;gt;sudo su cd /opt wget https://github.com/owasp-modsecurity/ModSecurity/releases...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
Going to be compiling &amp;lt;code&amp;gt;mod_security2&amp;lt;/code&amp;gt; (v2.9.7) for Apache2 on Ubuntu 22.04. This module is pretty straight forward to compile. However, there are some dependencies.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo apt install apache2-dev gcc libxml2 libxml2-dev libpcre3-dev&amp;lt;/pre&amp;gt;&lt;br /&gt;
Fetch the tarball from their github releases page.&lt;br /&gt;
&lt;br /&gt;
https://github.com/owasp-modsecurity/ModSecurity/releases/tag/v2.9.7&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo su&lt;br /&gt;
cd /opt&lt;br /&gt;
wget https://github.com/owasp-modsecurity/ModSecurity/releases/download/v2.9.7/modsecurity-2.9.7.tar.gz&lt;br /&gt;
tar -xzvf modsecurity-2.9.7.tar.gz&lt;br /&gt;
cd modsecurity-2.9.7&lt;br /&gt;
./configure --with-apxs=/usr/bin/apxs&lt;br /&gt;
make&lt;br /&gt;
make install&lt;br /&gt;
echo &#039;LoadModule security2_module /usr/lib/apache2/modules/mod_security2.so&#039; &amp;amp;gt; /etc/apache2/mods-available/security2.load&lt;br /&gt;
a2enmod security2&lt;br /&gt;
systemctl restart apache2&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then you should be able to see mod security enabled and working in the Apache error logs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[Wed Jul 17 19:25:21.038359 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity for Apache/2.9.7 (http://www.modsecurity.org/) configured.&lt;br /&gt;
[Wed Jul 17 19:25:21.038434 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: APR compiled version=&amp;amp;quot;1.7.0&amp;amp;quot;; loaded version=&amp;amp;quot;1.7.0&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038447 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: PCRE compiled version=&amp;amp;quot;8.39 &amp;amp;quot;; loaded version=&amp;amp;quot;8.39 2016-06-14&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038449 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: LIBXML compiled version=&amp;amp;quot;2.9.13&amp;amp;quot;&lt;br /&gt;
[Wed Jul 17 19:25:21.038549 2024] [security2:notice] [pid 1929:tid 140275463350144] ModSecurity: StatusEngine call: &amp;amp;quot;2.9.7,Apache/2.4.52 (Ubuntu),1.7.0/1.7.0,8.39/8.39 2016-06-14,(null),2.9.13,e013612419474187e43b03a4f546e0736dc12934&amp;amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Additional Resources ==&lt;br /&gt;
&lt;br /&gt;
Please see their official handbook for more details on compiling this module.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/owasp-modsecurity/ModSecurity/wiki/Reference-Manual-(v2.x)#installation-steps Reference-Manual-v2.x]&lt;br /&gt;
&lt;br /&gt;
Also be sure to run &amp;lt;code&amp;gt;./configure --help&amp;lt;/code&amp;gt; for more information about how to compile this for your system.&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Using_Iperf3_for_Speed_Testing&amp;diff=48</id>
		<title>Using Iperf3 for Speed Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Using_Iperf3_for_Speed_Testing&amp;diff=48"/>
		<updated>2024-05-18T21:11:17Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Just found out about a cool little utility called &amp;lt;code&amp;gt;iperf3&amp;lt;/code&amp;gt; for testing upload/download speeds between two hosts.&lt;br /&gt;
&lt;br /&gt;
On the server make sure to open the testing port on your firewall. Then run the following iperf3 command to start the server in your terminal.&lt;br /&gt;
&lt;br /&gt;
 iperf3 -s -p 4000&lt;br /&gt;
&lt;br /&gt;
I&#039;m running it on port 4000.&lt;br /&gt;
&lt;br /&gt;
Then from the client machine you can run the following to test upload speeds.&lt;br /&gt;
&lt;br /&gt;
 iperf3 -c SERVER_IP -p 4000 -t 10&lt;br /&gt;
&lt;br /&gt;
If you stick a &amp;lt;code&amp;gt;-R&amp;lt;/code&amp;gt; on there to reverse the direction (aka test download speeds).&lt;br /&gt;
&lt;br /&gt;
 iperf3 -c SERVER_IP -p 4000 -t 10 -R&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some example output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
» iperf3 -c REDACTED -p 4000 -t 10 -R&lt;br /&gt;
Connecting to host REDACTED, port 4000&lt;br /&gt;
Reverse mode, remote host REDACTED is sending&lt;br /&gt;
[  5] local 192.168.1.179 port 60750 connected to REDACTED port 4000&lt;br /&gt;
[ ID] Interval           Transfer     Bitrate&lt;br /&gt;
[  5]   0.00-1.00   sec  33.7 MBytes   283 Mbits/sec                  &lt;br /&gt;
[  5]   1.00-2.00   sec  31.3 MBytes   263 Mbits/sec                  &lt;br /&gt;
[  5]   2.00-3.00   sec  35.9 MBytes   301 Mbits/sec                  &lt;br /&gt;
[  5]   3.00-4.00   sec  32.1 MBytes   269 Mbits/sec                  &lt;br /&gt;
[  5]   4.00-5.00   sec  31.6 MBytes   265 Mbits/sec                  &lt;br /&gt;
[  5]   5.00-6.00   sec  30.3 MBytes   254 Mbits/sec                  &lt;br /&gt;
[  5]   6.00-7.00   sec  37.3 MBytes   313 Mbits/sec                  &lt;br /&gt;
[  5]   7.00-8.00   sec  34.0 MBytes   285 Mbits/sec                  &lt;br /&gt;
[  5]   8.00-9.00   sec  28.5 MBytes   239 Mbits/sec                  &lt;br /&gt;
[  5]   9.00-10.00  sec  29.1 MBytes   244 Mbits/sec                  &lt;br /&gt;
- - - - - - - - - - - - - - - - - - - - - - - - -&lt;br /&gt;
[ ID] Interval           Transfer     Bitrate         Retr&lt;br /&gt;
[  5]   0.00-10.04  sec   326 MBytes   272 Mbits/sec  649             sender&lt;br /&gt;
[  5]   0.00-10.00  sec   324 MBytes   272 Mbits/sec                  receiver&lt;br /&gt;
&lt;br /&gt;
iperf Done.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.oracle.com/cd/E88353_01/html/E37839/iperf3-1.html man iperf3 (1)]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Using_Iperf3_for_Speed_Testing&amp;diff=47</id>
		<title>Using Iperf3 for Speed Testing</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Using_Iperf3_for_Speed_Testing&amp;diff=47"/>
		<updated>2024-05-18T21:08:16Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;Just found out about a cool little utility called &amp;lt;code&amp;gt;iperf3&amp;lt;/code&amp;gt; for testing upload/download speeds between two hosts.  On the server make sure to open the testing port on your firewall. Then run the following iperf3 command to start the server in your terminal.   iperf3 -s -p 4000  I&amp;#039;m running it on port 4000.  Then from the client machine you can run the following to test upload speeds.   iperf3 -c SERVER_IP -p 4000 -t 10  If you stick a &amp;lt;code&amp;gt;-R&amp;lt;/code&amp;gt; on there t...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Just found out about a cool little utility called &amp;lt;code&amp;gt;iperf3&amp;lt;/code&amp;gt; for testing upload/download speeds between two hosts.&lt;br /&gt;
&lt;br /&gt;
On the server make sure to open the testing port on your firewall. Then run the following iperf3 command to start the server in your terminal.&lt;br /&gt;
&lt;br /&gt;
 iperf3 -s -p 4000&lt;br /&gt;
&lt;br /&gt;
I&#039;m running it on port 4000.&lt;br /&gt;
&lt;br /&gt;
Then from the client machine you can run the following to test upload speeds.&lt;br /&gt;
&lt;br /&gt;
 iperf3 -c SERVER_IP -p 4000 -t 10&lt;br /&gt;
&lt;br /&gt;
If you stick a &amp;lt;code&amp;gt;-R&amp;lt;/code&amp;gt; on there to reverse the direction (aka test download speeds).&lt;br /&gt;
&lt;br /&gt;
 iperf3 -c SERVER_IP -p 4000 -t 10 -R&lt;br /&gt;
&lt;br /&gt;
Here&#039;s some example output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
» iperf3 -c REDACTED -p 4000 -t 10 -R&lt;br /&gt;
Connecting to host REDACTED, port 4000&lt;br /&gt;
Reverse mode, remote host REDACTED is sending&lt;br /&gt;
[  5] local 192.168.1.179 port 60750 connected to REDACTED port 4000&lt;br /&gt;
[ ID] Interval           Transfer     Bitrate&lt;br /&gt;
[  5]   0.00-1.00   sec  33.7 MBytes   283 Mbits/sec                  &lt;br /&gt;
[  5]   1.00-2.00   sec  31.3 MBytes   263 Mbits/sec                  &lt;br /&gt;
[  5]   2.00-3.00   sec  35.9 MBytes   301 Mbits/sec                  &lt;br /&gt;
[  5]   3.00-4.00   sec  32.1 MBytes   269 Mbits/sec                  &lt;br /&gt;
[  5]   4.00-5.00   sec  31.6 MBytes   265 Mbits/sec                  &lt;br /&gt;
[  5]   5.00-6.00   sec  30.3 MBytes   254 Mbits/sec                  &lt;br /&gt;
[  5]   6.00-7.00   sec  37.3 MBytes   313 Mbits/sec                  &lt;br /&gt;
[  5]   7.00-8.00   sec  34.0 MBytes   285 Mbits/sec                  &lt;br /&gt;
[  5]   8.00-9.00   sec  28.5 MBytes   239 Mbits/sec                  &lt;br /&gt;
[  5]   9.00-10.00  sec  29.1 MBytes   244 Mbits/sec                  &lt;br /&gt;
- - - - - - - - - - - - - - - - - - - - - - - - -&lt;br /&gt;
[ ID] Interval           Transfer     Bitrate         Retr&lt;br /&gt;
[  5]   0.00-10.04  sec   326 MBytes   272 Mbits/sec  649             sender&lt;br /&gt;
[  5]   0.00-10.00  sec   324 MBytes   272 Mbits/sec                  receiver&lt;br /&gt;
&lt;br /&gt;
iperf Done.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=46</id>
		<title>Keeping Sensitive Data Out of Your Shells History File</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=46"/>
		<updated>2024-05-17T17:40:15Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We&#039;ve all been there before. &amp;lt;code&amp;gt;some_command&amp;lt;/code&amp;gt; takes a flag for --password or --api_key. The lazy thing to do is just supply the password as part of your command. But there are two big downsides of doing that. First, it goes into your shell&#039;s history file and if you just leave it there someone could find it and use it to steal your bits! Second it goes into the process list and is potentially visible to other users on the system who are just viewing the process tree.&lt;br /&gt;
&lt;br /&gt;
Luckily, there&#039;s a simple way to solve both of these problems and its called &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Technically, read is not a stand alone executable, but rather a bash builtin. But all the shell&#039;s have it or an equivalent. Bash, zsh, fish all have &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Csh/tcsh has &amp;lt;code&amp;gt;$&amp;lt;&amp;lt;/code&amp;gt; (works basically the same).&lt;br /&gt;
&lt;br /&gt;
Bash/Zsh Example:&lt;br /&gt;
&lt;br /&gt;
 read mypass&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
 mypass=&amp;quot;&amp;quot; # Reset value after use or just logout&lt;br /&gt;
&lt;br /&gt;
Csh/Tcsh Example:&lt;br /&gt;
&lt;br /&gt;
 setenv mypass $&amp;lt;&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
 setenv mypass &amp;quot;&amp;quot; # Reset value after use or just logout&lt;br /&gt;
&lt;br /&gt;
With bash read you can even run &amp;lt;code&amp;gt;read -s mypass&amp;lt;/code&amp;gt; to be extra super duper secure and hide your password when entering it.&lt;br /&gt;
&lt;br /&gt;
Maybe people know about using read in a script but you can just use it on the CLI too to keep your sensitive credentials or other info out of your bash history &amp;amp; system process list.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading!&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=45</id>
		<title>Keeping Sensitive Data Out of Your Shells History File</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=45"/>
		<updated>2024-05-17T17:37:45Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We&#039;ve all been there before. &amp;lt;code&amp;gt;some_command&amp;lt;/code&amp;gt; takes a flag for --password or --api_key. The lazy thing to do is just supply the password as part of your command. But there are two big downsides of doing that. First, it goes into your shell&#039;s history file and if you just leave it there someone could find it and use it to steal your bits! Second it goes into the process list and is potentially visible to other users on the system who are just viewing the process tree.&lt;br /&gt;
&lt;br /&gt;
Luckily, there&#039;s a simple way to solve both of these problems and its called &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Technically, read is not a stand alone executable, but rather a bash builtin. But all the shell&#039;s have it or an equivalent. Bash, zsh, fish all have &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Csh/tcsh has &amp;lt;code&amp;gt;$&amp;lt;&amp;lt;/code&amp;gt; (works basically the same).&lt;br /&gt;
&lt;br /&gt;
Bash/Zsh Example:&lt;br /&gt;
&lt;br /&gt;
 read mypass&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
 mypass=&amp;quot;&amp;quot; # Reset value after use or just logout&lt;br /&gt;
&lt;br /&gt;
Csh/Tcsh Example:&lt;br /&gt;
&lt;br /&gt;
 setenv mypass $&amp;lt;&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
 setenv fart &amp;quot;&amp;quot; # Reset value after use or just logout&lt;br /&gt;
&lt;br /&gt;
With bash read you can even run &amp;lt;code&amp;gt;read -s mypass&amp;lt;/code&amp;gt; to be extra super duper secure and hide your password when entering it.&lt;br /&gt;
&lt;br /&gt;
Maybe people know about using read in a script but you can just use it on the CLI too to keep your sensitive credentials or other info out of your bash history &amp;amp; system process list.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading!&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=44</id>
		<title>Keeping Sensitive Data Out of Your Shells History File</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=44"/>
		<updated>2024-05-17T17:37:20Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We&#039;ve all been there before. &amp;lt;code&amp;gt;some_command&amp;lt;/code&amp;gt; takes a flag for --password or --api_key. The lazy thing to do is just supply the password as part of your command. But there are two big downsides of doing that. First, it goes into your shell&#039;s history file and if you just leave it there someone could find it and use it to steal your bits! Second it goes into the process list and is potentially visible to other users on the system who are just viewing the process tree.&lt;br /&gt;
&lt;br /&gt;
Luckily, there&#039;s a simple way to solve both of these problems and its called &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Technically, read is not a stand alone executable, but rather a bash builtin. But all the shell&#039;s have it or an equivalent. Bash, zsh, fish all have &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Csh/tcsh has &amp;lt;code&amp;gt;$&amp;lt;&amp;lt;/code&amp;gt; (works basically the same).&lt;br /&gt;
&lt;br /&gt;
Bash/Zsh Example:&lt;br /&gt;
&lt;br /&gt;
 read mypass&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
 mypass=&#039;&#039; # Reset value after use or just logout&lt;br /&gt;
&lt;br /&gt;
Csh/Tcsh Example:&lt;br /&gt;
&lt;br /&gt;
 setenv mypass $&amp;lt;&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
 setenv fart &#039;&#039; # Reset value after use or just logout&lt;br /&gt;
&lt;br /&gt;
With bash read you can even run &amp;lt;code&amp;gt;read -s mypass&amp;lt;/code&amp;gt; to be extra super duper secure and hide your password when entering it.&lt;br /&gt;
&lt;br /&gt;
Maybe people know about using read in a script but you can just use it on the CLI too to keep your sensitive credentials or other info out of your bash history &amp;amp; system process list.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading!&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=43</id>
		<title>Keeping Sensitive Data Out of Your Shells History File</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Keeping_Sensitive_Data_Out_of_Your_Shells_History_File&amp;diff=43"/>
		<updated>2024-05-17T17:31:51Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;We&amp;#039;ve all been there before. &amp;lt;code&amp;gt;some_command&amp;lt;/code&amp;gt; takes a flag for --password or --api_key. The lazy thing to do is just supply the password as part of your command. But there are two big downsides of doing that. First, it goes into your shell&amp;#039;s history file and if you just leave it there someone could find it and use it to steal your bits! Second it goes into the process list and is potentially visible to other users on the system who are just viewing the process t...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We&#039;ve all been there before. &amp;lt;code&amp;gt;some_command&amp;lt;/code&amp;gt; takes a flag for --password or --api_key. The lazy thing to do is just supply the password as part of your command. But there are two big downsides of doing that. First, it goes into your shell&#039;s history file and if you just leave it there someone could find it and use it to steal your bits! Second it goes into the process list and is potentially visible to other users on the system who are just viewing the process tree.&lt;br /&gt;
&lt;br /&gt;
Luckily, there&#039;s a simple way to solve both of these problems and its called &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Technically, read is not a stand alone executable, but rather a bash builtin. But all the shell&#039;s have it or an equivalent. Bash, zsh, fish all have &amp;lt;code&amp;gt;read&amp;lt;/code&amp;gt;. Csh/tcsh has &amp;lt;code&amp;gt;$&amp;lt;&amp;lt;/code&amp;gt; (works basically the same).&lt;br /&gt;
&lt;br /&gt;
Bash/Zsh Example:&lt;br /&gt;
&lt;br /&gt;
 read mypass&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Csh/Tcsh Example:&lt;br /&gt;
&lt;br /&gt;
 setenv mypass $&amp;lt;&lt;br /&gt;
 TYPE_SOME_PASSWORD_HERE&lt;br /&gt;
 some_command --user username --password &amp;quot;$mypass&amp;quot;&lt;br /&gt;
&lt;br /&gt;
With bash read you can even run &amp;lt;code&amp;gt;read -s mypass&amp;lt;/code&amp;gt; to be extra super duper secure and hide your password when entering it.&lt;br /&gt;
&lt;br /&gt;
Maybe people know about using read in a script but you can just use it on the CLI too to keep your sensitive credentials or other info out of your bash history &amp;amp; system process list.&lt;br /&gt;
&lt;br /&gt;
Thanks for reading!&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Do_cmd_X_times_without_a_forloop&amp;diff=42</id>
		<title>Do cmd X times without a forloop</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Do_cmd_X_times_without_a_forloop&amp;diff=42"/>
		<updated>2024-04-30T01:09:31Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;Say you&amp;#039;re in a weird shell and you don&amp;#039;t know how to do a forloop. No worries! You can use seq | xargs to run some command any number of times.   seq 5 | xargs -I {} echo fart&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Say you&#039;re in a weird shell and you don&#039;t know how to do a forloop. No worries! You can use seq | xargs to run some command any number of times.&lt;br /&gt;
&lt;br /&gt;
 seq 5 | xargs -I {} echo fart&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Japh&amp;diff=41</id>
		<title>Japh</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Japh&amp;diff=41"/>
		<updated>2024-04-13T10:41:33Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;A perl japh is an obfuscated perl program that prints out the message &amp;lt;code&amp;gt;Just another Perl Hacker&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Just another Perl Programmer&amp;lt;/code&amp;gt;.  Here&amp;#039;s my first ever attempt at creating a japh.  &amp;lt;pre&amp;gt; #!/usr/bin/env perl # John&amp;#039;s first japh! use MIME::Base64;use Compress::Zlib;$s=&amp;#039;blue23&amp;#039;;$p=&amp;#039;japh&amp;#039;;@k=split  &amp;#039;&amp;#039;,crypt($p,$s);%h=(&amp;#039;1&amp;#039;=&amp;gt;&amp;#039;CEgt&amp;#039;,&amp;#039;Y&amp;#039;=&amp;gt;&amp;#039;CNk=&amp;#039;,&amp;#039;0&amp;#039;=&amp;gt;&amp;#039;UUjM&amp;#039;,&amp;#039;Q&amp;#039;=&amp;gt;&amp;#039;Ti0C &amp;#039;,&amp;#039;w&amp;#039;=&amp;gt;&amp;#039;SEzO&amp;#039;,&amp;#039;l&amp;#039;=&amp;gt;&amp;#039;Ki0u&amp;#039;,&amp;#039;2&amp;#039;=&amp;gt;&amp;#039;SC1S&amp;#039;,&amp;#039;3&amp;#039;=&amp;gt;&amp;#039;yy/J&amp;#039;,&amp;#039;U&amp;#039;=&amp;gt;undef,&amp;#039;7&amp;#039;=&amp;gt; undef,&amp;#039;x&amp;#039;=&amp;gt;&amp;#039;ylHw&amp;#039;,&amp;#039;N&amp;#039;...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A perl japh is an obfuscated perl program that prints out the message &amp;lt;code&amp;gt;Just another Perl Hacker&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Just another Perl Programmer&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s my first ever attempt at creating a japh.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env perl&lt;br /&gt;
# John&#039;s first japh!&lt;br /&gt;
use MIME::Base64;use Compress::Zlib;$s=&#039;blue23&#039;;$p=&#039;japh&#039;;@k=split &lt;br /&gt;
&#039;&#039;,crypt($p,$s);%h=(&#039;1&#039;=&amp;gt;&#039;CEgt&#039;,&#039;Y&#039;=&amp;gt;&#039;CNk=&#039;,&#039;0&#039;=&amp;gt;&#039;UUjM&#039;,&#039;Q&#039;=&amp;gt;&#039;Ti0C&lt;br /&gt;
&#039;,&#039;w&#039;=&amp;gt;&#039;SEzO&#039;,&#039;l&#039;=&amp;gt;&#039;Ki0u&#039;,&#039;2&#039;=&amp;gt;&#039;SC1S&#039;,&#039;3&#039;=&amp;gt;&#039;yy/J&#039;,&#039;U&#039;=&amp;gt;undef,&#039;7&#039;=&amp;gt;&lt;br /&gt;
undef,&#039;x&#039;=&amp;gt;&#039;ylHw&#039;,&#039;N&#039;=&amp;gt;&#039;AG8p&#039;,&#039;b&#039;=&amp;gt;&#039;eJzz&#039;);$japh;foreach (@k){next &lt;br /&gt;
unless $h{$_};$japh.=$h{$_};};print uncompress(decode_base64($japh&lt;br /&gt;
)).&amp;quot;\n&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When run it output:&lt;br /&gt;
 ./japh.pl&lt;br /&gt;
 Just another Perl Hacker&lt;br /&gt;
&lt;br /&gt;
[https://www.perlmonks.org/?node_id=412464 More info]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Encode.php&amp;diff=40</id>
		<title>Encode.php</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Encode.php&amp;diff=40"/>
		<updated>2024-04-11T04:08:12Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;Encodes a file as base64 gzip compressed payload file.  &amp;lt;pre&amp;gt; &amp;lt;?php $input_file = &amp;#039;info.php&amp;#039;; $output_file = &amp;#039;x.php&amp;#039;;  function removePhpTags($content) {   $content = preg_replace(&amp;#039;/^&amp;lt;\?php\s*/&amp;#039;, &amp;#039;&amp;#039;, $content);   $content = preg_replace(&amp;#039;/\s*\?&amp;gt;$/&amp;#039;, &amp;#039;&amp;#039;, $content);   return $content; }  $file_content = file_get_contents($input_file); $file_content = removePhpTags($file_content);  $encoded = base64_encode(gzcompress($file_content)); $payload = &amp;quot;&amp;lt;?php eval(gzuncompress(base...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Encodes a file as base64 gzip compressed payload file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$input_file = &#039;info.php&#039;;&lt;br /&gt;
$output_file = &#039;x.php&#039;;&lt;br /&gt;
&lt;br /&gt;
function removePhpTags($content) {&lt;br /&gt;
  $content = preg_replace(&#039;/^&amp;lt;\?php\s*/&#039;, &#039;&#039;, $content);&lt;br /&gt;
  $content = preg_replace(&#039;/\s*\?&amp;gt;$/&#039;, &#039;&#039;, $content);&lt;br /&gt;
  return $content;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$file_content = file_get_contents($input_file);&lt;br /&gt;
$file_content = removePhpTags($file_content);&lt;br /&gt;
&lt;br /&gt;
$encoded = base64_encode(gzcompress($file_content));&lt;br /&gt;
$payload = &amp;quot;&amp;lt;?php eval(gzuncompress(base64_decode(&#039;$encoded&#039;)));?&amp;gt;&amp;quot;;&lt;br /&gt;
file_put_contents($output_file, $payload);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=39</id>
		<title>Virsh list all in json</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Virsh_list_all_in_json&amp;diff=39"/>
		<updated>2023-12-31T03:14:26Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; command will list all virsh guests in json.   echo &amp;quot;[ $(virsh list --all|grep -Ev &amp;#039;Id|----&amp;#039;|awk &amp;#039;{print &amp;quot;{ \&amp;quot;id\&amp;quot;: \&amp;quot;&amp;quot;$1&amp;quot;\&amp;quot;, \&amp;quot;name\&amp;quot;: \&amp;quot;&amp;quot;$2&amp;quot;\&amp;quot;, \&amp;quot;state\&amp;quot;: \&amp;quot;&amp;quot;$3 $4&amp;quot;\&amp;quot;},&amp;quot; }&amp;#039;|head -n -1) {} ]&amp;quot;|jq -r  Output example:  &amp;lt;pre&amp;gt; [   {     &amp;quot;id&amp;quot;: &amp;quot;38&amp;quot;,     &amp;quot;name&amp;quot;: &amp;quot;Mac&amp;quot;,     &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;   },   {     &amp;quot;id&amp;quot;: &amp;quot;39&amp;quot;,     &amp;quot;name&amp;quot;: &amp;quot;Dennis&amp;quot;,     &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;   },   {     &amp;quot;id&amp;quot;: &amp;quot;40&amp;quot;,     &amp;quot;name&amp;quot;: &amp;quot;Charlie&amp;quot;,     &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;   }, ... &amp;lt;/pre&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following &amp;lt;code&amp;gt;bash&amp;lt;/code&amp;gt; command will list all virsh guests in json.&lt;br /&gt;
&lt;br /&gt;
 echo &amp;quot;[ $(virsh list --all|grep -Ev &#039;Id|----&#039;|awk &#039;{print &amp;quot;{ \&amp;quot;id\&amp;quot;: \&amp;quot;&amp;quot;$1&amp;quot;\&amp;quot;, \&amp;quot;name\&amp;quot;: \&amp;quot;&amp;quot;$2&amp;quot;\&amp;quot;, \&amp;quot;state\&amp;quot;: \&amp;quot;&amp;quot;$3 $4&amp;quot;\&amp;quot;},&amp;quot; }&#039;|head -n -1) {} ]&amp;quot;|jq -r&lt;br /&gt;
&lt;br /&gt;
Output example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;38&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Mac&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;39&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Dennis&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;40&amp;quot;,&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;Charlie&amp;quot;,&lt;br /&gt;
    &amp;quot;state&amp;quot;: &amp;quot;running&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Loris.php&amp;diff=38</id>
		<title>Loris.php</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Loris.php&amp;diff=38"/>
		<updated>2023-12-14T04:00:31Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;Useful little PHP script for holding a connection open for testing.  &amp;lt;pre&amp;gt; &amp;lt;?php // John testing holding a connection open, will clean up. Although I guess if // you&amp;#039;re reading this that was a lie, sorry... /* Debug */ ini_set(&amp;#039;display_errors&amp;#039;,&amp;#039;1&amp;#039;); ini_set(&amp;#039;display_startup_errors&amp;#039;,&amp;#039;1&amp;#039;); error_reporting (E_ALL);  echo &amp;quot;Randomness Begin...&amp;quot;;  function random_string($length) {     $str = random_bytes($length);     $str = base64_encode($str);     $str = str_replace([&amp;quot;+&amp;quot;, &amp;quot;/...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Useful little PHP script for holding a connection open for testing.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// John testing holding a connection open, will clean up. Although I guess if&lt;br /&gt;
// you&#039;re reading this that was a lie, sorry...&lt;br /&gt;
/* Debug&lt;br /&gt;
*/&lt;br /&gt;
ini_set(&#039;display_errors&#039;,&#039;1&#039;);&lt;br /&gt;
ini_set(&#039;display_startup_errors&#039;,&#039;1&#039;);&lt;br /&gt;
error_reporting (E_ALL);&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Randomness Begin...&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
function random_string($length) {&lt;br /&gt;
    $str = random_bytes($length);&lt;br /&gt;
    $str = base64_encode($str);&lt;br /&gt;
    $str = str_replace([&amp;quot;+&amp;quot;, &amp;quot;/&amp;quot;, &amp;quot;=&amp;quot;], &amp;quot;&amp;quot;, $str);&lt;br /&gt;
    $str = substr($str, 0, $length);&lt;br /&gt;
    return $str;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
while (True) {&lt;br /&gt;
    echo random_string(32) .&amp;quot;\n&amp;lt;br&amp;gt;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Inotifywait_Shenanigans&amp;diff=37</id>
		<title>Inotifywait Shenanigans</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Inotifywait_Shenanigans&amp;diff=37"/>
		<updated>2023-12-02T05:34:11Z</updated>

		<summary type="html">&lt;p&gt;Admin: /* Exec on Cat */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inotifywait ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
From the [https://linux.die.net/man/1/inotifywait man page].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NAME&lt;br /&gt;
       inotifywait, fsnotifywait - wait for changes to files using inotify or fanotify&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
       inotifywait  efficiently waits for changes to files using Linux&#039;s inotify(7) interface.  It is&lt;br /&gt;
       suitable for waiting for changes to files from shell scripts.  It  can  either  exit  once  an&lt;br /&gt;
       event occurs, or continually execute and output events as they occur.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Cat on Write ===&lt;br /&gt;
&lt;br /&gt;
* Term 1: inotifywait listener&lt;br /&gt;
&lt;br /&gt;
 » notifywait -qqe close_write fart.txt &amp;amp;&amp;amp; cat fart.txt&lt;br /&gt;
&lt;br /&gt;
Args are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       -e &amp;lt;event&amp;gt;, --event &amp;lt;event&amp;gt;&lt;br /&gt;
              Listen  for specific event(s) only.  The events which can be listened for are listed in&lt;br /&gt;
              the EVENTS section.  This option can be specified more  than  once.   If  omitted,  all&lt;br /&gt;
              events are listened for.&lt;br /&gt;
&lt;br /&gt;
        -q, --quiet&lt;br /&gt;
              If specified once, the program will be less verbose.  Specifically, it will  not  state&lt;br /&gt;
              when it has completed establishing all inotify watches.&lt;br /&gt;
&lt;br /&gt;
              If specified twice, the program will output nothing at all, except in the case of fatal&lt;br /&gt;
              errors.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://linux.die.net/man/1/inotifywait Man inotifywait]&lt;br /&gt;
&lt;br /&gt;
* Term 2: Write to fart.txt&lt;br /&gt;
&lt;br /&gt;
 » echo fart fart fart &amp;gt; fart.txt&lt;br /&gt;
&lt;br /&gt;
* Term 1: fart.txt catt&#039;ed&lt;br /&gt;
&lt;br /&gt;
 » notifywait -qqe close_write fart.txt &amp;amp;&amp;amp; cat fart.txt&lt;br /&gt;
 fart fart fart&lt;br /&gt;
&lt;br /&gt;
Well now you might say &amp;quot;interesting but what good is that?&amp;quot; Well with a slight modification we can set a bit of a trap.&lt;br /&gt;
&lt;br /&gt;
=== Exec on Cat  👨‍💼/🐱 ===&lt;br /&gt;
&lt;br /&gt;
* Term 1: Set Tripwire&lt;br /&gt;
&lt;br /&gt;
 » inotifywait -qqe open fart.txt &amp;amp;&amp;amp; ./run_hax.sh&lt;br /&gt;
&lt;br /&gt;
* Term 2: Harmlessly Cat a File&lt;br /&gt;
 » cat fart.txt&lt;br /&gt;
&lt;br /&gt;
* Term 1: Hax Triggered!&lt;br /&gt;
 » inotifywait -qqe open fart.txt &amp;amp;&amp;amp; ./run_hax.sh&lt;br /&gt;
 Running Hax...&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes&lt;br /&gt;
&lt;br /&gt;
https://linux.die.net/man/1/inotifywait&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Inotifywait_Shenanigans&amp;diff=36</id>
		<title>Inotifywait Shenanigans</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Inotifywait_Shenanigans&amp;diff=36"/>
		<updated>2023-12-02T03:06:09Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inotifywait ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
From the [https://linux.die.net/man/1/inotifywait man page].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NAME&lt;br /&gt;
       inotifywait, fsnotifywait - wait for changes to files using inotify or fanotify&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
       inotifywait  efficiently waits for changes to files using Linux&#039;s inotify(7) interface.  It is&lt;br /&gt;
       suitable for waiting for changes to files from shell scripts.  It  can  either  exit  once  an&lt;br /&gt;
       event occurs, or continually execute and output events as they occur.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Cat on Write ===&lt;br /&gt;
&lt;br /&gt;
* Term 1: inotifywait listener&lt;br /&gt;
&lt;br /&gt;
 » notifywait -qqe close_write fart.txt &amp;amp;&amp;amp; cat fart.txt&lt;br /&gt;
&lt;br /&gt;
Args are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       -e &amp;lt;event&amp;gt;, --event &amp;lt;event&amp;gt;&lt;br /&gt;
              Listen  for specific event(s) only.  The events which can be listened for are listed in&lt;br /&gt;
              the EVENTS section.  This option can be specified more  than  once.   If  omitted,  all&lt;br /&gt;
              events are listened for.&lt;br /&gt;
&lt;br /&gt;
        -q, --quiet&lt;br /&gt;
              If specified once, the program will be less verbose.  Specifically, it will  not  state&lt;br /&gt;
              when it has completed establishing all inotify watches.&lt;br /&gt;
&lt;br /&gt;
              If specified twice, the program will output nothing at all, except in the case of fatal&lt;br /&gt;
              errors.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://linux.die.net/man/1/inotifywait Man inotifywait]&lt;br /&gt;
&lt;br /&gt;
* Term 2: Write to fart.txt&lt;br /&gt;
&lt;br /&gt;
 » echo fart fart fart &amp;gt; fart.txt&lt;br /&gt;
&lt;br /&gt;
* Term 1: fart.txt catt&#039;ed&lt;br /&gt;
&lt;br /&gt;
 » notifywait -qqe close_write fart.txt &amp;amp;&amp;amp; cat fart.txt&lt;br /&gt;
 fart fart fart&lt;br /&gt;
&lt;br /&gt;
Well now you might say &amp;quot;interesting but what good is that?&amp;quot; Well with a slight modification we can set a bit of a trap.&lt;br /&gt;
&lt;br /&gt;
=== Exec on Cat ===&lt;br /&gt;
&lt;br /&gt;
* Term 1: Set Tripwire&lt;br /&gt;
&lt;br /&gt;
 » inotifywait -qqe open fart.txt &amp;amp;&amp;amp; ./run_hax.sh&lt;br /&gt;
&lt;br /&gt;
* Term 2: Harmlessly Cat a File&lt;br /&gt;
 » cat fart.txt&lt;br /&gt;
&lt;br /&gt;
* Term 1: Hax Triggered!&lt;br /&gt;
 » inotifywait -qqe open fart.txt &amp;amp;&amp;amp; ./run_hax.sh&lt;br /&gt;
 Running Hax...&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes&lt;br /&gt;
&lt;br /&gt;
https://linux.die.net/man/1/inotifywait&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Inotifywait_Shenanigans&amp;diff=35</id>
		<title>Inotifywait Shenanigans</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Inotifywait_Shenanigans&amp;diff=35"/>
		<updated>2023-12-02T03:04:39Z</updated>

		<summary type="html">&lt;p&gt;Admin: Created page with &amp;quot;== Inotifywait ==  === Description ===  From the [https://linux.die.net/man/1/inotifywait man page].  &amp;lt;pre&amp;gt; NAME        inotifywait, fsnotifywait - wait for changes to files using inotify or fanotify  DESCRIPTION        inotifywait  efficiently waits for changes to files using Linux&amp;#039;s inotify(7) interface.  It is        suitable for waiting for changes to files from shell scripts.  It  can  either  exit  once  an        event occurs, or continually execute and output eve...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inotifywait ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
From the [https://linux.die.net/man/1/inotifywait man page].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NAME&lt;br /&gt;
       inotifywait, fsnotifywait - wait for changes to files using inotify or fanotify&lt;br /&gt;
&lt;br /&gt;
DESCRIPTION&lt;br /&gt;
       inotifywait  efficiently waits for changes to files using Linux&#039;s inotify(7) interface.  It is&lt;br /&gt;
       suitable for waiting for changes to files from shell scripts.  It  can  either  exit  once  an&lt;br /&gt;
       event occurs, or continually execute and output events as they occur.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Cat on Write ===&lt;br /&gt;
&lt;br /&gt;
* Term 1: inotifywait listener&lt;br /&gt;
&lt;br /&gt;
 » notifywait -qqe close_write fart.txt &amp;amp;&amp;amp; cat fart.txt&lt;br /&gt;
&lt;br /&gt;
Args are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
       -e &amp;lt;event&amp;gt;, --event &amp;lt;event&amp;gt;&lt;br /&gt;
              Listen  for specific event(s) only.  The events which can be listened for are listed in&lt;br /&gt;
              the EVENTS section.  This option can be specified more  than  once.   If  omitted,  all&lt;br /&gt;
              events are listened for.&lt;br /&gt;
&lt;br /&gt;
        -q, --quiet&lt;br /&gt;
              If specified once, the program will be less verbose.  Specifically, it will  not  state&lt;br /&gt;
              when it has completed establishing all inotify watches.&lt;br /&gt;
&lt;br /&gt;
              If specified twice, the program will output nothing at all, except in the case of fatal&lt;br /&gt;
              errors.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://linux.die.net/man/1/inotifywait Man inotifywait]&lt;br /&gt;
&lt;br /&gt;
* Term 2: Write to fart.txt&lt;br /&gt;
&lt;br /&gt;
 » echo fart fart fart &amp;gt; fart.txt&lt;br /&gt;
&lt;br /&gt;
* Term 1: fart.txt catt&#039;ed&lt;br /&gt;
&lt;br /&gt;
 » notifywait -qqe close_write fart.txt &amp;amp;&amp;amp; cat fart.txt&lt;br /&gt;
 fart fart fart&lt;br /&gt;
&lt;br /&gt;
Well now you might say &amp;quot;interesting but what good is that?&amp;quot; Well with a slight modification we can set a bit of a trap.&lt;br /&gt;
&lt;br /&gt;
=== Exec on Cat ===&lt;br /&gt;
&lt;br /&gt;
* Term 1: Set Tripwire&lt;br /&gt;
&lt;br /&gt;
 » inotifywait -qqe open fart.txt&lt;br /&gt;
&lt;br /&gt;
* Term 2: Harmlessly Cat a File&lt;br /&gt;
 » cat fart.txt&lt;br /&gt;
&lt;br /&gt;
* Term 1: Hax Triggered!&lt;br /&gt;
 » inotifywait -qqe open fart.txt &amp;amp;&amp;amp; ./run_hax.sh&lt;br /&gt;
 Running Hax...&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes&lt;br /&gt;
&lt;br /&gt;
https://linux.die.net/man/1/inotifywait&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Using_the_FTP_CLI_Utility&amp;diff=34</id>
		<title>Using the FTP CLI Utility</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Using_the_FTP_CLI_Utility&amp;diff=34"/>
		<updated>2023-10-19T19:32:29Z</updated>

		<summary type="html">&lt;p&gt;Admin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To use the FTP command line utility run the command below.&lt;br /&gt;
&lt;br /&gt;
 ftp example.com&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Connected to example.com.&lt;br /&gt;
220 ProFTPD Server (example.com FTP server)&lt;br /&gt;
Name (example.com): YOUR_USERNAME               &lt;br /&gt;
331 Password required for YOUR_USERNAME&lt;br /&gt;
Password:&lt;br /&gt;
230 User YOUR_USERNAME logged in&lt;br /&gt;
Remote system type is UNIX.&lt;br /&gt;
Using binary mode to transfer files.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Then enable passive mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ftp&amp;amp;gt; passive&lt;br /&gt;
Passive mode on.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You can list files with &amp;lt;code&amp;gt;ls&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;dir&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ftp&amp;amp;gt; ls&lt;br /&gt;
227 Entering Passive Mode.&lt;br /&gt;
150 Opening BINARY mode data connection for file list&lt;br /&gt;
app.js	bin 	public_ftp   &lt;br /&gt;
backup	public_html  www_logs&lt;br /&gt;
226 Transfer complete&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Pull a file down from the server with the &amp;lt;code&amp;gt;get&amp;lt;/code&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ftp&amp;amp;gt; get app.js&lt;br /&gt;
local: app.js remote: app.js&lt;br /&gt;
227 Entering Passive Mode (66,39,65,154,129,77).&lt;br /&gt;
150 Opening BINARY mode data connection for app.js (338 bytes)&lt;br /&gt;
226 Transfer complete&lt;br /&gt;
338 bytes received in 0.00 secs (1.2446 MB/s)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Then disconnect and you can see you have the file on your client machine:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ftp&amp;amp;gt; exit&lt;br /&gt;
221 Goodbye.&lt;br /&gt;
&lt;br /&gt;
blue@Home:$~&amp;amp;gt; cat app.js&lt;br /&gt;
const http = require(&#039;http&#039;);&lt;br /&gt;
&lt;br /&gt;
const hostname = &#039;127.0.0.1&#039;;&lt;br /&gt;
const port = 3000;&lt;br /&gt;
...&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You run commands on your local machine through the ftp shell by prefixing a ! char:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ftp&amp;amp;gt; !cat blah.txt&lt;br /&gt;
blah blah blah&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To upload a file to a server use the &amp;lt;code&amp;gt;put&amp;lt;/code&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ftp&amp;amp;gt; put blah.txt&lt;br /&gt;
local: blah.txt remote: blah.txt&lt;br /&gt;
227 Entering Passive Mode (66,39,65,154,129,91).&lt;br /&gt;
150 Opening BINARY mode data connection for blah.txt&lt;br /&gt;
226 Transfer complete&lt;br /&gt;
5 bytes sent in 0.00 secs (256.9901 kB/s)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* And then if we check on the remote machine via ftp we can see:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;john@server:$~&amp;amp;gt; cat blah.txt&lt;br /&gt;
fart&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To see a help menu for ftp run help:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ftp&amp;gt; help&lt;br /&gt;
Commands may be abbreviated.  Commands are:&lt;br /&gt;
&lt;br /&gt;
!           edit        lpage       nlist       rcvbuf      struct&lt;br /&gt;
$           epsv        lpwd        nmap        recv        sunique&lt;br /&gt;
account     epsv4       ls          ntrans      reget       system&lt;br /&gt;
append      epsv6       macdef      open        remopts     tenex&lt;br /&gt;
ascii       exit        mdelete     page        rename      throttle&lt;br /&gt;
bell        features    mdir        passive     reset       trace&lt;br /&gt;
binary      fget        mget        pdir        restart     type&lt;br /&gt;
bye         form        mkdir       pls         rhelp       umask&lt;br /&gt;
case        ftp         mls         pmlsd       rmdir       unset&lt;br /&gt;
cd          gate        mlsd        preserve    rstatus     usage&lt;br /&gt;
cdup        get         mlst        progress    runique     user&lt;br /&gt;
chmod       glob        mode        prompt      send        verbose&lt;br /&gt;
close       hash        modtime     proxy       sendport    xferbuf&lt;br /&gt;
cr          help        more        put         set         ?   &lt;br /&gt;
debug       idle        mput        pwd         site&lt;br /&gt;
delete      image       mreget      quit        size&lt;br /&gt;
dir         lcd         msend       quote       sndbuf&lt;br /&gt;
disconnect  less        newer       rate        status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Help for specific command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;ftp&amp;amp;gt; help lcd&lt;br /&gt;
lcd         change local working directory&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
	<entry>
		<id>https://wiki.johnlradford.io/index.php?title=Editing_Bats_-_Bash_Automated_Testing_System&amp;diff=33</id>
		<title>Editing Bats - Bash Automated Testing System</title>
		<link rel="alternate" type="text/html" href="https://wiki.johnlradford.io/index.php?title=Editing_Bats_-_Bash_Automated_Testing_System&amp;diff=33"/>
		<updated>2023-10-07T11:11:24Z</updated>

		<summary type="html">&lt;p&gt;Admin: Admin moved page Editing Bats - Bash Automated Testing System to Bats - Bash Automated Testing System: Misspelled title: Goofed when copying source from og wiki.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Bats - Bash Automated Testing System]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>