Langsung ke konten utama

Nginx Block Sqlinjection

Nah saya Bagikan Script Nginx untuk block sqlinjection, caranya:

$ sudo vim /etc/nginx/sites-available/namawebsite.com.conf

tambah baris didalam server { } berikut:

server {
[...]

   ## Block SQL injections
   set $block_sql_injections 0;
   if ($query_string ~ "union.*select.*\(") {
       set $block_sql_injections 1;
   }
   if ($query_string ~ "union.*all.*select.*") {
       set $block_sql_injections 1;
   }
   if ($query_string ~ "concat.*\(") {
       set $block_sql_injections 1;
   }
   if ($block_sql_injections = 1) {
       return 403;
   }

   ## Block file injections
   set $block_file_injections 0;
   if ($query_string ~ "[a-zA-Z0-9_]=http://") {
       set $block_file_injections 1;
   }
   if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
       set $block_file_injections 1;
   }
   if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
       set $block_file_injections 1;
   }
   if ($block_file_injections = 1) {
       return 403;
   }

   ## Block common exploits
   set $block_common_exploits 0;
   if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
       set $block_common_exploits 1;
   }
   if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
       set $block_common_exploits 1;
   }
   if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
       set $block_common_exploits 1;
   }
   if ($query_string ~ "proc/self/environ") {
       set $block_common_exploits 1;
   }
   if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
       set $block_common_exploits 1;
   }
   if ($query_string ~ "base64_(en|de)code\(.*\)") {
       set $block_common_exploits 1;
   }
   if ($block_common_exploits = 1) {
       return 403;
   }

   ## Block spam
   set $block_spam 0;
   if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
       set $block_spam 1;
   }
   if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
       set $block_spam 1;
   }
   if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
       set $block_spam 1;
   }
   if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
       set $block_spam 1;
   }
   if ($block_spam = 1) {
       return 403;
   }

   ## Block user agents
   set $block_user_agents 0;

   # Don't disable wget if you need it to run cron jobs!
   #if ($http_user_agent ~ "Wget") {
   #    set $block_user_agents 1;
   #}

   # Disable Akeeba Remote Control 2.5 and earlier
   if ($http_user_agent ~ "Indy Library") {
       set $block_user_agents 1;
   }

   # Common bandwidth hoggers and hacking tools.
   if ($http_user_agent ~ "libwww-perl") {
       set $block_user_agents 1;
   }
   if ($http_user_agent ~ "GetRight") {
       set $block_user_agents 1;
   }
   if ($http_user_agent ~ "GetWeb!") {
       set $block_user_agents 1;
   }
   if ($http_user_agent ~ "Go!Zilla") {
       set $block_user_agents 1;
   }
   if ($http_user_agent ~ "Download Demon") {
       set $block_user_agents 1;
   }
   if ($http_user_agent ~ "Go-Ahead-Got-It") {
       set $block_user_agents 1;
   }
   if ($http_user_agent ~ "TurnitinBot") {
       set $block_user_agents 1;
   }
   if ($http_user_agent ~ "GrabNet") {
       set $block_user_agents 1;
   }

   if ($block_user_agents = 1) {
       return 403;
   }
   set $block_xss 0;
if ($query_string ~ "base64_(en|de)code\(.*\)") {
set $block_xss 1;
}
if ($request_uri ~ "base64_(en|de)code\(.*\)") {
set $block_xss 1;
}
if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
set $block_xss 1;
}
if ($request_uri ~ "(<|%3C).*script.*(>|%3E)") {
set $block_xss 1;
}
if ($query_string ~ "(<|%3C).*iframe.*(>|%3E)") {
set $block_xss 1;
}
if ($request_uri ~ "(<|%3C).*iframe.*(>|%3E)") {
set $block_xss 1;
}
if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
       set $block_xss 1;
}
if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
       set $block_xss 1;
}
if ($block_xss = 1) {
return 403;
}
   
[...]
}

Komentar

Postingan populer dari blog ini

Tutorial Install SQLmap Ubuntu

sqlmap merupakan tools/alat opensource yang mendeteksi dan melakukan exploit pada Bug SQLinjection. dengan melakukan serangan SQL injection, peretas dapat mengambil alih hingga dapat memanipulasi sebuah database di dalam sebuah server. Sebelumnya, apa itu SQL Injection? SQL injection merupakan teknik hacking di mana peretas dapat menyisipkan perintah-perintah SQL melalu URL untuk di eksekusi oleh database. bug atau vulnerability ini terjadi karena kelalian seorang programer atau webmaster dalam melakukan pemograman web seperti tidak difilternya variabel dalam web tersebut. Cara installnya? $ sudo apt-get install git $ git clone https://github.com/sqlmapproject/sqlmap.git Untuk Menjalankannya, $ cd /patch/to/sqlmap/ jalankan dengan perintah dasar $ python sqlmap.py -h << untuk melihat basic options $ python sqlmap.py -u 'http://alamat.com'  contoh lain: $ python sqlmap.py --url=”http://192.168.152.129/dvwa/vulnerabilities/sqli/? id=1&Submit=S

PHP Apps in a Subdirectory in Nginx

 location /pilkades {     alias /var/www/html/pilkades;     try_files $uri $uri/ @nested;     location ~ \.php$ {         include snippets/fastcgi-php.conf;         fastcgi_param SCRIPT_FILENAME $request_filename;         fastcgi_pass unix:/run/php/php7.4-fpm.sock;     } } location @pilkades {     rewrite /pilkades/(.*)$ /pilkades/index.php?/$1 last; } atau: location /alias {     alias  /var/www/htmlalias;     location ~ /([^/]+\.php)$ {       try_files /$1 =404;       fastcgi_pass unix:/var/run/php5-fpm.sock;       fastcgi_index index.php;       include fastcgi_params;       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;     }   }

Backup Mysql ALL Database with Specific Methods ( #! /bin/bash)

#! /bin/bash # backup-mysql.sh # # Craig Sanders <cas@taz.net.au> # this script is in the public domain.  do whatever you want with it. MYUSER="root" MYPWD="PASSWD" ARGS="--single-transaction --flush-logs --complete-insert" DATABASES=$( mysql -D mysql --skip-column-names -B -e 'show databases;' | egrep -v 'information_schema' ); BACKUPDIR=/var/backups/mysql YEAR=$(date +"%Y") MONTH=$(date +"%m") DAY=$(date +"%d") DATE="$YEAR-$MONTH/$YEAR-$MONTH-$DAY" mkdir -p $BACKUPDIR/$DATE cd $BACKUPDIR/$DATE for i in $DATABASES ; do   echo -n "backing up $i: schema..."   mysqldump $ARGS --no-data -u$MYUSER -p$MYPWD $i > $i.schema.sql   echo -n "data..."   mysqldump $ARGS --skip-opt --no-create-db --no-create-info -u$MYUSER -p$MYPWD $i > $i.data.sql   echo -n "backup full databases"   mysqldump $ARGS -u$MYUSER -p$MYPWD $i > $i.full.sql   echo -n "Backup views"