Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some profiles produce invalid regex #1

Open
tophertimzen opened this issue Dec 19, 2017 · 0 comments
Open

Some profiles produce invalid regex #1

tophertimzen opened this issue Dec 19, 2017 · 0 comments

Comments

@tophertimzen
Copy link

I am using the mod rewrite script on some Malleable C2 profiles, one being https://github.com/rsmudge/Malleable-C2-Profiles/blob/master/normal/amazon.profile, and it produces invalid regex.

I feel it should be producing, ^/(/s/ref=nb_sb_noss_1/167-3294888-0262949/field-keywords=book|/N4215/adj/amzn.us.sr.ap)/?$, which will properly redirect to my C2 (tested) on matching URI. The script as is produces !^/(/s/ref=nb_sb_noss_1/167-3294888-0262949/field-keywords=book|/N4215/adj/amzn.us.sr.ap)/?$ which doesn't match. (The trailing '!' is the difference which I believe is negating the result of the condition making it never hit the [P] ReWriteRule.)

The following patch made the amazon C2 profile work, but I haven't tested it on the others.

diff --git a/apache_redirector_setup.py b/apache_redirector_setup.py
index dd3083a..38c4efa 100644
--- a/apache_redirector_setup.py
+++ b/apache_redirector_setup.py
@@ -321,7 +321,7 @@ def validURI(uris, block_url, block_mode,server_root):
         old.close()
         if len(uris) == 1:
             finalURI = uris[0]
-            rule = 'RewriteCond %{REQUEST_URI} !^' + finalURI + '?$ [NC]\n'
+            rule = 'RewriteCond %{REQUEST_URI} ^' + finalURI + '?$ [NC]\n'
         else:
             for uri in uris:
                 if uri == uris[len(uris)-1]:
@@ -329,7 +329,7 @@ def validURI(uris, block_url, block_mode,server_root):
                 else:
                     finalURI += uri + "|"
 
-            rule = 'RewriteCond %{REQUEST_URI} !^/(' + finalURI + ')/?$ [NC]\n'
+            rule = 'RewriteCond %{REQUEST_URI} ^/(' + finalURI + ')/?$ [NC]\n'
         if block_mode == "redirect":
             rule = rule + 'RewriteRule ^.*$ ' + block_url + '/? [L,R=302]\n'
         elif block_mode == "proxy":
@@ -354,7 +354,7 @@ def validURI(uris, block_url, block_mode,server_root):
                     finalURI += uri + "|"
 
         rule = "RewriteEngine On\n"
-        rule += 'RewriteCond %{REQUEST_URI} !^/(' + finalURI + ')/?$ [NC]'
+        rule += 'RewriteCond %{REQUEST_URI} ^/(' + finalURI + ')/?$ [NC]'
         if block_mode == "redirect":
             rule = rule + 'RewriteRule ^.*$ ' + block_url + '/? [L,R=302]\n'
         elif block_mode == "proxy":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant