Questions tagged [regex]
When asking regex questions, always add the tag for the specific programming language or tool (e.g., Perl, Python, or Java; vi, emacs, or ɢɴᴜ grep; etc.) you are using.
729
questions
0
votes
1
answer
52
views
Fail2Ban RegEx works but filter does not
my plan is to ban all accesses to my webserver which repeatedly produce 404-errors and obviously do some scanning only
For this I tried
fail2ban-regex /var/log/apache2/otheraccess.log '^<HOST>. -...
0
votes
2
answers
101
views
Fail2Ban: RegEx to filter all 404 errors out of the Apache-log
In my logs I regularly see loads of 404-errors where bots obviously do scan the server systematically for specific software installations. As this also causes loads of traffic, I want to ban them.
So ...
0
votes
3
answers
261
views
Shell script capturing values from output of command
From a shell script, I run a ping command:
ping -c4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=34.2 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 ...
0
votes
0
answers
76
views
nginx replace given character globally in url
I have a legacy backend wich doesn't interpret url-encoded %2B as a + sign in urls like
http://10.20.30.40/keyvalues?Name=foo%2Bbar%2Bbaz%2B...
http://10.20.30.40/keyvalues?Name=foo%2Bbaz
http://10.20....
0
votes
1
answer
67
views
How to apply multiple filters in asterisk 20.4.0 AMI interface
I just want to filter all event that contains "Event: Hangup and "Channel: PJSIP/ANCONA_UFFICIO" against an event like this:
Event: Hangup
Privilege: call,all
Channel: PJSIP/...
0
votes
2
answers
198
views
IF statement based on comparison with %{REQUEST_URI} in .htaccess doesn't work
I'm trying to send a custom header for pages that start with /test-live/
The code I tried:
<If "%{REQUEST_URI} =~ m#^/test-live/#">
Header always set X-Frame-Options "...
-1
votes
1
answer
272
views
Crafting regex for Fail2ban and NGINX
I'm having some trouble understanding how to craft a regex to capture probe attempts on my nginx webserver.
I would like to craft a filter to catch sites hitting certain files (by name) and/or by php ...
0
votes
0
answers
62
views
Fail2ban rule not working, nginx basic auth
I have a regexp like this that is used in my fail2ban jail
^ \[error\] \d+#\d+: \*\d+ user "\S+":? (password mismatch|was not found in ".*"), client: <HOST>, server: \S+, ...
0
votes
1
answer
94
views
Remove trailing slash on nginx except for certaing URLs
I'm removing the trailing slash in a nginx virtual host using the following code but I would like to prevent that from happening when the url has certaing words or slusg like i.e /bar/ or /foo/ etc.
...
0
votes
0
answers
26
views
libmodsecurity + owasp crs + nginx: regex for hyphen in name of a POST parameter in custom exclude rule
a paranoia_level = 3 of modsecurity forbids non-printable characters to be uploaded with POST payloads (application/x-www-form-urlencoded) in phase 2 using rule 920272 of owasp crs version 3.3.4
But, ...
1
vote
1
answer
148
views
Regexp in Apache 2.4 when used in HTTP_USER_AGENT var
I need to work with some user-agents in Apache 2.4. I googled a lot for examples, tried a million regex options, and it still doesn't work:
<If "%{HTTP_USER_AGENT} == '/^.*(Google|bing|Windows|...
0
votes
2
answers
293
views
IIS Redirect Rule to redirect all subdomain traffic
I have this rewrite rule defined in the web.config file on my site:
<rule name="RedirectWwwToNonWww" enabled="true" stopProcessing="false">
<match url="(.*...
0
votes
0
answers
102
views
nginx regex not matching the url
I have an issue with nginx, which after simplifying everything (just a single location directive) reduces to
location ~ ^/api/pages/user/.*$ {
return 200 "This is a dummy response for /api/user/...
0
votes
0
answers
156
views
Sudo validates command line arguments via regular expression incorrectly
Let's say we have two users: alex and alexa. We want to allow alex to execute htop as root in order to see disk usage stats, but we do not want them to see other users' processes which root can do. ...
0
votes
1
answer
763
views
Nginx check if parameters exists and if so only allow specific values
I cant seem to find a way to limit some queries. Right now i have this
if ($args ~* "(.*&)?page="){
set $wrongP W;
}
if ($args !~* (.*&)?page=(2|12|24)$){
set $wrongP "${...
0
votes
1
answer
414
views
Fail2ban apache2 access log regex
Can anyone help me with fail2ban regex
My goal is to ban any accessing .env or .php files or any request that starts with "wp-", it is a little bit confusing
and another to detect invalid ...
0
votes
0
answers
148
views
Using Rank Math REgex for subfolder redirects to home
So short summary: im a SEO specialist working on a website that has over 1000 404 pages due to a translator app. The subfolders /de/ /fr/ /es/ /en/ and URL's within the subfolder need to be redirected ...
0
votes
1
answer
53
views
Regular expression does not work in EMEditor
I have a simple Regular expression to select all text between X-Mozilla-Status and [Chat Info]. I tried it at https://regexr.com/, and it all works great. However, it can't find anything if I add it ...
0
votes
1
answer
110
views
Can't get Samba smv.conf shadow copy snapprefix to recognise snaps
I'm really with this one. What I'm aiming for is that snpshots with an optional tag at the front, as well as untagged snaps are seen in windows as previous copies, e.g. file names such as:
/mnt/pool1/....
0
votes
2
answers
173
views
Unable to compile regular expression in Fail2Ban
I'm trying to get this regex working in Fail2Ban:
SRC=(?<ADDR>.*) DST.*(?=DPT=5003)
In a regex tester it's working very fine. When testing in Fail2Ban, I get this error:
ERROR: Unable to ...
0
votes
1
answer
202
views
linux fail2ban not catching auth a specific fail with postfix
I had journalctl open and noticed an offender repeatedly hitting me with auth fails in postfix. I have a standard postfix-sasl filter on by default that, to my knowledge, is working well.
It wasn't ...
0
votes
0
answers
288
views
NGINX - How to serve file with filename that begins with the last segment of uri?
I have many PDFs in a \drawings folder on my server. The filename structure is: 8 digits, underscore, Rev level letter -- i.e. \d{8}_[A-Za-z]\.pdf. These files are organized in subfolders that match ...
0
votes
0
answers
489
views
fail2ban block plex failed login attempts
I want to ban IPs who attempt to authenticate against my public Plex instance.
Im on Ubuntu and the log Im looking at is the following:
/var/lib/plexmediaserver/Library/Application\ Support/Plex\ ...
0
votes
0
answers
50
views
regex puppet query syntax
I'm trying to learn how to use puppet query, but I'm finding it difficult to target a particular fact path using regex.
If I use the following query, I get exactly what I'm looking for:
puppet-query '...
0
votes
1
answer
368
views
NGINX reverse_proxy with subpath and regex
I have a site running on localhost:8001 and I would like it to be accessible on different paths. I need to extract part of the path using regex.
This does work:
server {
location /user/amy/ {
...
1
vote
1
answer
418
views
Virtual domain variable in postfix/smtp_header_checks
What Postfix virtual domain variable should I use in outgoing header creation?
Current server
I'm running a database-driven virtual domain server managed by PostfixAdmin. I want to put statements in ...
1
vote
0
answers
370
views
modsecurity regex not always matching simple rule
Im trying to create a simple modsecurity regex rule that stops processing the rules when a match is found and just returns status 200 on a POST request so that it doesnt continue and get blocked by ...
0
votes
1
answer
182
views
How to make an regex in Fail2ban with ip:port
First of all, English is not mu native language, so if I make a mistake don't shoot me. :)
Here's my problem: when I use every thing works fine, as soon as there is a port number or a comma direct ...
0
votes
0
answers
176
views
REQENV and SETIF If statement isn't evaluating correctly
....or it is and I've missed something.
So I have a website that can only be accessed via certain IPs. A new development is that I want some of the pages on the site to be open and freely available to ...
0
votes
1
answer
2k
views
Nginx split the URI into variables to use on proxy_pass
I'm tring to get the URI parts to then pass it to the proxy_pass url. But I don't know about regex to do this.
I need to get the first and last URI into a variables to pass it on the proxy_pass like ...
0
votes
1
answer
82
views
RegEx passed by CSV file not working in PowerShell
Hi I have a script trying to pull out the price value from a html file. the Regex works when I assign it in the script but when I put the regex in CSV, it refuses to give me the result. Could someone ...
0
votes
0
answers
357
views
Fail2ban regex not banning IP address
I have the following jail added to jail.local file:
[nginx-honeypot]
enabled = true
filter = nginx-honeypot
port = http,https
logpath = /var/log/nginx/access.log
maxretry = 1
bantime = 86400
I ...
0
votes
1
answer
369
views
Bacula fileset wildcards: how include /folder/(arbitrary string)/uploads but exclude /folder/(arbitrary string)/whatever/uploads
I'm creating an exclude rule for bacula so it doesn't take care of some cache and temporary uploads folders inside a filesystem. But I'm failing to write it
Suppose this filesystem
/filestore/user1/
/...
0
votes
0
answers
71
views
fail2ban regex failing to work
I am trying to create a regex for my fail2ban filter to block all IPs that get a incorrect login on a web application. The way I distinguish this is that each login generates a GET request in the ...
0
votes
1
answer
615
views
nginx url rewrite regex with special characters
How to write a regex that matches a path node with reserved characters like '+','-' ? for example:
https://e.example.com/foo+/bar/file/test.txt need to be re-written as https://e.example.com/bar/file/...
0
votes
1
answer
809
views
what the meaning of "logpath = %(nginx_error_log)s" in fail2ban jail log path?
I am running fail2ban on Ubuntu 20.04 server, and am looking over some of the default jails. In [nginx-http-auth] the default log path shows as logpath = %(nginx_error_log)s. What exactly does %(...
0
votes
1
answer
225
views
Need a regular expression to match 3-member simple series
I need a regex that would match the following example strings:
Example 1: "red, blue, and hot"
Example 2: "red, blue, or hot"
Three individual words, the first two followed by ...
0
votes
1
answer
1k
views
How to redirect all pages that contain a specific word using the .htaccess file
I have a bunch of indexed pages that start with the same word and they are all 404 so I want to redirect them all to the homepage of the site. The server is Apache, so I would like to use the ....
0
votes
1
answer
131
views
Odd behavior of bash array
I've recently encountered a strange script behavior and still don't understand y the array behaves this way.
Here is a piece of the script:
for nCDATAReg in $(seq 1 4)
do
sTestBuffer1=$(...
1
vote
1
answer
754
views
Redirect all URLs ending in ".-detail" to remove the dot
I have a rather odd situation where our old URLs are ending in .-detail and need changing to just -detail.
For example:
example.com/product.-detail needs changing to example.com/product-detail
In ...
0
votes
1
answer
554
views
Dynamically move mails into matching mailboxes with sieve fileinto regex
I'm trying to create a sieve script, which files mails into mailboxes (or sub-directories of the inbox) matching a certain subject identifier.
For example if the subject includes 123 (three digits, 0-...
0
votes
1
answer
272
views
RegEx for 301 redirects to change path AND remove a string
I am looking for an RegEX redirect rule to redirect the image file locations to a new location, whilst also removing part of the original url which is the name of the image
OLD URL:
/components/...
0
votes
1
answer
519
views
Ansible Findall capture groups and list
I think I'm confused with Python and Ansible findall. Can I use capture groups in Ansible? For example, How can I capture group 1 and group 2 then reverse the position in the resulting list?
For ...
0
votes
1
answer
780
views
Nginx reverse proxy base URI to change port
Hi i want reverse proxy my Nginx base port used
for example
http://example.com:443/ips/8443 -> http://example.com:8443/ips/8443
http://example.com:443/ips/23950 -> http://example.com:23950/ips/...
1
vote
1
answer
2k
views
Regexp header_checks in postfix for a match over multiple lines
Here's my /etc/postfix/main.cf header_checks line:
header_checks = regexp:/etc/postfix/maps/header_checks
And here is header_checks:
/From:.*email@my\.com.(\n|.)*?To:.*email@my\.com./ DISCARD
...
0
votes
1
answer
250
views
Implementing arithmetic rules in sieve to filter recipient address, is it possible?
For example, the receiver's address should have the following pattern:
last digit = (1st digit + 2nd digit)%10.
[email protected], PASS, 1+2=3, and the last digit is 3.
[email protected], ...
0
votes
1
answer
431
views
Playbook to extract hosts from /etc/hosts
I need help extracting hosts informations from /etc/hosts file and exporting that content to a predefined file. I created a Ansible's Playbook to this task, but the content is not written on the ...
0
votes
0
answers
97
views
Regular expression for url longer than 3 characters Nginx
There is a website site.ru/
I need to write a regular expression where pages longer than 3 characters only work after the first slash. If in this case there are other pages after the slash, then 404 ...
0
votes
1
answer
59
views
Nginx: try_fiiles directive with variable from path
I have set up a server block that looks like this:
root /var/www/platform
location / {
index index.html;
}
location /contact {
try_files $uri /contact.html;
}
This works fine. I can go to x.com/...
1
vote
1
answer
351
views
.htaccess redirect if param value not portuguese-pt (FORCE WHMCS ONLY ONE LANG)
I need help to redirect URLs with multiple language codes to one with .htaccess. The following URLs should redirect:
https://example.com/cp/cart.php?a=add&pid=7&language=us
https://example....