Simple Honeypot For Django Admin

farzin haque
3 min readDec 11, 2020

I think first it’s better to figure it out: what is Honeypot?

In simple words honeypot is a kind of trap to detect people who attempts at unauthorized access of some important part of our Information system like Admin panel.A Honeypot usually consists of data that appears to be a legitimate or important part of the site that seems to contain information or a resource of value to attackers, but actually, it is isolated and monitored and enables blocking or analyzing the attackers, like a copy of login admin panel that seems like a real Django Login Admin Panel but it’s not, and that is what we want to do here.

For this I’m going to use django-admin-honeypot library and for sending email to admins I’m using Mailtrap, you can use your Gmail too.

  1. Initiating Django project:
python3 -m venv venv
source venv/bin/activate
pip install django
django-admin startproject myHoneypot

2. Installing django-admin-honeypot and migrate create superuser

pip install django-admin-honeypot
python manage.py migrate
python manage.py createsuperuser

3. Add admin_honeypot to INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
...
'admin_honeypot',
...
]

4. Update urls.py :

from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path(‘admin-panel/’, admin.site.urls),
path(‘admin/’, include(‘admin_honeypot.urls’, namespace=’admin_honeypot’)),
]

Now my real admin panel path changed to admin-panel/ and admin/ is my honeypot path.

5. You can config your Django settings to send an email to admins for every unauthorized access for this purpose, this module use mail_admins() method.

For sending Email we need an email service you can use your Gmail but I’m going to use Mailtrap.

Insettings.py :

# Admin's name and email to send email to them
ADMINS = (
(‘Farzin’, ‘myemail@gmail.com’),
)
# You need this variable to be able to send email
EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
# Mailtrap, Gmail or your service email config
EMAIL_HOST = ‘smtp.mailtrap.io’
EMAIL_HOST_USER = ‘123234234asd’
EMAIL_HOST_PASSWORD = ‘1232343545asd’
EMAIL_PORT = ‘2525’
Mailtrap option Django email config

You can find Mailtrap configs for Django by opening Demo inbox im mail trap account and choosing Django from Integrations dropdown item.

5. run:

python manage.py runserver

and go to:

12.0.0.1:8000/admin

you will see admin login panel try to log in you will see something like this:

django-admin-panel

Notice: even if you try to login with super user, you will get this error, it’s because of security purpose.

now go to:

12.0.0.1:8000/admin-panel

and try to login in your panel you can see a new item like below:

django-panel

If you click on Login attempts you can see all unauthorized attempts and for each of them you have this informations:

logs

6. Now you can check your Mailtrap inbox and you have a surprise!

mailtrap-email

And that’s it.

Stay safe and secure & enjoy coding :)

--

--

farzin haque

Software developer, Cyber Security, GNU/Linux and Machine learning enthusiast