Skip to content

Commit 24cbf80

Browse files
Merge pull request #64 from theMiddleBlue/v2.3/master
Improve regex filters
2 parents 2fcad78 + fffe95e commit 24cbf80

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

functions_nmap.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def nmap_scaninfo(request):
3838

3939
def nmap_newscan(request):
4040
if request.method == "POST":
41-
if(re.search('^[a-zA-Z0-9\_\-\.]+$', request.POST['filename']) and not (re.search('[\||\;|\&}]', request.POST['params']) or re.search('[\||\;|\&}]', request.POST['target']))):
41+
if(re.search('^[a-zA-Z0-9\_\-\.]+$', request.POST['filename']) and re.search('^[a-zA-Z0-9\-\.\:\=\s]+$', request.POST['params']) and re.search('^[a-zA-Z0-9\-\.\:]+$', request.POST['target'])):
4242
res = {'p':request.POST}
4343
os.popen('nmap '+request.POST['params']+' --script='+settings.BASE_DIR+'/nmapreport/nmap/nse/ -oX /tmp/'+request.POST['filename']+'.active '+request.POST['target']+' > /dev/null 2>&1 && '+
4444
'sleep 10 && mv /tmp/'+request.POST['filename']+'.active /opt/xml/'+request.POST['filename']+' &')
@@ -51,3 +51,6 @@ def nmap_newscan(request):
5151
file.write(json.dumps(schedobj, indent=4))
5252

5353
return HttpResponse(json.dumps(res, indent=4), content_type="application/json")
54+
else:
55+
res = {'error':'invalid syntax'}
56+
return HttpResponse(json.dumps(res, indent=4), content_type="application/json")

static/async.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ function newscan() {
193193

194194
function startscan() {
195195
$('#modal1').modal('close');
196-
swal("Started", "Your new Nmap scan is running...", "success");
197196
csrftoken = $('input[name="csrfmiddlewaretoken"]').val();
198197
$.post('/api/v1/nmap/scan/new', {
199198
'csrfmiddlewaretoken': csrftoken,
@@ -203,7 +202,11 @@ function startscan() {
203202
'schedule': $('#schedule').prop('checked'),
204203
'frequency': $('#frequency').val(),
205204
}).done(function(d) {
206-
console.log(d);
205+
if(typeof(d['error']) != 'undefined') {
206+
swal("Error", "Invalid syntax or disallowed characters", "error");
207+
} else {
208+
swal("Started", "Your new Nmap scan is running...", "success");
209+
}
207210
});
208211
}
209212

0 commit comments

Comments
 (0)