Score:0

Apache2 how to generate random string for subdomain

fr flag

I want to issue a redirect to a new randomly generated subdomain name for every request I get. Below you can find my vhost configuration. I want to do a redirect towards a subdomain containing some random alphanumeric string in . It's ok if it is something as basic as the datetime+ip of a client or something like that, I just need to do some fingerprinting, it doesn't have to be more complex. Is there a way I can generate that via some script and plug it into the vhost for every request, an existing file with available options of random strings or some kind of regex?

<VirtualHost *:443>
    ServerName mysite.com
            Redirect 302 / https://<randomstring>.mysite.com/
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined
            SSLEngine on
            SSLCertificateFile      /etc/apache2/ssl/site.cert
            SSLCertificateKeyFile /etc/apache2/ssl/site.key
</VirtualHost>

My OS is ubuntu 20.04

Score:1
la flag

The Redirect directive expects a fixed URL. So that won't work.

The easiest will probably to use mod_rewrite to redirect all requests to script and then let your script, for example a redirect.php PHP script, which has access to a proper RANDOM function, generate the random redirect.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /redirect.php [L]

Using mod_rewrite to directly generate a random redirect ins't possible AFAIK, no random function is provided.

A possible work-around: activate mod_unique_id and you get access to pretty good random environment variable.

Then:

RewriteEngine On
RewriteRule . http://%{UNIQUE_ID}.example.com [R]
Mnemosyne avatar
fr flag
thank you very much for your suggestions. I tried to implement the unique_id option however the formatting you provided above does not seem to work for the rewrite rule. The unique ID is generated but not parsed in the domain. The location sent back to the client ends up being "https://.example.com" instead of "https:// UNIQUE_ID .example.com". I am using your formatting here. Is there some parsing requirement I am missing?
diya avatar
la flag
It might be necessary to enclose the arguments in the RewriteRule with `"` double quotes. i.e. `RewriteRule ".*" "http://%{UNIQUE_ID}.example.com" [R]` or something.
Mnemosyne avatar
fr flag
Hi. I already tried enclosing it in the double quotes. It still does not appear in the location response.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.