Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spambots are cluttering my log file [Django]

I have a nice and lovely Django site up and running, but have noticed that my error.log file was getting huge, over 150 MB after a couple of months of being live. Turns out a bunch of spambots are looking for well known URL vulnerabilities (or something) and hitting a bunch of sub-directories like http://mysite.com/ie or http://mysite.com/~admin.php etc.

Since Django uses URL rewriting, it is looking for templates to fit these requests, which raises a TemplateDoesNotExist exception, and then a 500 message (Django does this, not me). I have debug turned off, so they only get the generic 500 message, but it's filling up my logs very quickly.

Is there a way to turn this behavior off? Or perhaps just block the IP's doing this?

like image 640
swilliams Avatar asked Dec 03 '22 16:12

swilliams


2 Answers

Um, perhaps, use logrotate to rotate and compress the logs periodically, if it isn't being done already.

like image 105
ayaz Avatar answered Dec 21 '22 09:12

ayaz


If you can find a pattern in UserAgent string, you may use DISALLOWED_USER_AGENT setting. Mine is:

DISALLOWED_USER_AGENTS = (
    re.compile(r'Java'),
    re.compile(r'gigamega'),
    re.compile(r'litefinder'),
)

See the description in Django docs.

like image 37
zgoda Avatar answered Dec 21 '22 07:12

zgoda