Stephan Miller
.htaccess Hack Finder Script for vlag-nerto.ru

.htaccess Hack Finder Script for vlag-nerto.ru

A few day ago, I posted about a Wordpress .htaccess redirect hack that happened to me.

So I wrote a Python script that will help me find any .htaccess files that had the redirect domain. I uploaded it to my home folder in my server. Then used SSH to run it. Any Linux server most likely has Python installed. So you can run this script using:

python htaccess_hack_finder.py

It will then print out:

Bad: /location/of/bad

Each time it finds the string, which in my case was a few times for each file. Then you just open your FTP, find the bad files and remove the hack. This script will actually work to find any string in an .htaccess file.

import os
#Replace with name of directory to scan, i.e, your WP directory
dir = "/var/www/"
#Replace with string to find, in my case, this domain, which my site was redirecting to
to_find = "vlag-nerto.ru"
for root, dirs, files in os.walk(dir):
for file in files:
fullpath = os.path.join(root, file)
#if os.path.splitext(fullpath)[1] == '.php':
if file == '.htaccess':
f = open(fullpath)
for line in f:
if line.find(to_find) > -1:
print "Bad: " + fullpath
else:
pass
#print "Good: " + fullpath

Stephan Miller

Written by

Kansas City Software Engineer and Author

Twitter | Github | LinkedIn

Updated