Landing pages for hackers

This post is going to be about NGINX wizardry. Not really.

This post is going to be about curl, since we all know real hackers use curl for everything.

We check the weather in it with

curl wttr.in  

we check our IP in it with

curl icanhazip.com  

we search for command options in it with

curl cheat.sh  

we bake pancakes in it with

curl -d {} pancak.es/bake  

Just kidding.

But curl is seriously bad ass and I use it every day to debug server responses with Chrome's nifty copy as curl feature.

So why does nobody make landing pages for it?


It's not that hard, just tweak your NGINX config a little.

Your config is probably already set up to redirect all HTTP traffic to HTTPS, at least that's what you should do if you want to have an adequate rating on Google. This was a problem for us since we now want to allow non-HTTPS traffic and serve some ASCII wizardry on http://twobucks.co.

We want to use HTTP for this to allow

curl twobucks.co  

in terminal, instead of the full URL.

To do this, we have to write a rule in NGINX that will redirect only if the user agent is not curl. The config file for that will look something like this

server {  
    listen 443;

    server_name twobucks.co;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/twobucks.co/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/twobucks.co/privkey.pem;

    client_max_body_size 10G;

    location / {
      autoindex on;
      root /path/to/your/assets;
      error_page  404   /404.html;
      fastcgi_intercept_errors on;
    }
}

server {  
    listen      80;
    server_name twobucks.co;

    location / {
            if ($http_user_agent ~ curl) {
                    root /path/to/your/curl/landing/page/;
            }
    }

    if ($http_user_agent !~ curl){
            return 301 https://twobucks.co$request_uri;
    }
}

You'll notice an if condition, we still want to preserve a 301 redirect when user agent is not curl. If we are using curl then we want to render a HTML page with ASCII characters tailored for it.

We converted our logo from PNG to ASCII format by using the awesome image-to-ascii.

That's all that was needed to get nice landing page inside of the terminal that looks like this:


Looks like no one is using this technique to display cool landing pages inside terminals. Maybe we can start a trend?


Like this post? Follow @shimewastaken on Twitter for more content like this.