Skip to content

Commit 469ac71

Browse files
committed
Add LDAP injection feature
1 parent 6472de8 commit 469ac71

File tree

11 files changed

+422
-255
lines changed

11 files changed

+422
-255
lines changed

config/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,7 @@
193193
MAIL_PASSWORD = 'test'
194194
MAIL_ADMIN_ADDRESS = 'root@localhost'
195195

196-
IS_ONLY_VULNERABILITIES = False
196+
IS_ONLY_VULNERABILITIES = False
197+
198+
LDAP_HOST = 'localhost'
199+
LDAP_PORT = 389

easybuggy/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
url(r'^mailheaderijct/$', views.mailheaderijct, name='mailheaderijct'),
3232
url(r'^unrestrictedsizeupload/$', views.unrestrictedsizeupload, name='unrestrictedsizeupload'),
3333
url(r'^unrestrictedextupload/$', views.unrestrictedextupload, name='unrestrictedextupload'),
34+
url(r'^ldapijc/*', views.ldapijc, name='ldapijc'),
3435
url(r'^bruteforce/*', views.bruteforce, name='bruteforce'),
3536
url(r'^openredirect/*', views.openredirect, name='openredirect'),
3637
url(r'^verbosemsg/*', views.verbosemsg, name='verbosemsg'),

easybuggy/views.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
from django import forms
1818
from django.conf import settings
1919
from django.contrib.auth import authenticate, login, logout
20+
from django.contrib.auth.backends import UserModel
2021
from django.db import transaction, connection, DatabaseError
2122
from django.http import HttpResponse
2223
from django.shortcuts import render, redirect
2324
from django.template.defaultfilters import filesizeformat
24-
from django.utils.baseconv import base64
2525
from django.utils.translation import ugettext as _
2626
from django.views.decorators.csrf import csrf_exempt
27+
from ldap3 import Server, Connection, ALL
28+
from ldap3.core.exceptions import LDAPExceptionError
2729

2830
from .forms import UploadFileForm
2931
from .models import User
@@ -54,6 +56,7 @@ def index(request):
5456
}
5557
if 'dlpinit' in request.session:
5658
del request.session['dlpinit']
59+
5760
return render(request, 'index.html', d)
5861

5962

@@ -174,6 +177,57 @@ def admins_login(request):
174177
return render(request, 'login.html', d)
175178

176179

180+
def ldapijc(request):
181+
if request.user.is_authenticated:
182+
return main(request)
183+
else:
184+
d = {
185+
'title': _('title.login.page'),
186+
'note': _('msg.note.ldap.injection'),
187+
}
188+
if request.method == 'GET':
189+
return render(request, 'login.html', d)
190+
elif request.method == 'POST':
191+
username = request.POST.get("username")
192+
password = request.POST.get("password")
193+
194+
if is_account_lockedout(username):
195+
d['errmsg'] = _("msg.authentication.fail")
196+
else:
197+
username = request.POST.get("username")
198+
password = request.POST.get("password")
199+
try:
200+
server = Server(settings.LDAP_HOST, settings.LDAP_PORT, get_info=ALL)
201+
conn = Connection(server, 'uid=admin,ou=people,dc=t246osslab,dc=org', 'password', auto_bind=True)
202+
conn.search('ou=people,dc=t246osslab,dc=org',
203+
'(&(uid=' + username + ')(userPassword=' + password + '))',
204+
attributes=['uid']) # TODO trim
205+
if len(conn.entries) > 0:
206+
user = UserModel._default_manager.get_by_natural_key(conn.entries[0].uid)
207+
login(request, user)
208+
# authentication succeeded, then reset account lock
209+
reset_account_lock(username)
210+
request.session["username"] = username
211+
if 'target' not in request.session:
212+
return main(request)
213+
else:
214+
target = request.session['target']
215+
del request.session['target']
216+
return redirect(target)
217+
else:
218+
d['errmsg'] = _("msg.authentication.fail")
219+
# account lock count +1
220+
increment_account_lock_num(username)
221+
222+
except LDAPExceptionError as le:
223+
d['errmsg'] = _("msg.ldap.access.fail")
224+
except Exception as e:
225+
logger.exception('Exception occurs: %s', e)
226+
d['errmsg'] = _('msg.unknown.exception.occur') + ": " + str(e)
227+
228+
return render(request, 'login.html', d)
229+
230+
177231
def bruteforce(request):
178232
if request.user.is_authenticated:
179233
return main(request)

locale/en/LC_MESSAGES/django.mo

642 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)