Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to check for response other than 200 OK #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions DetectDynamicJS.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from array import array
from time import sleep
import difflib
import re
except ImportError:
print "Failed to load dependencies. This issue maybe caused by using an unstable Jython version."

Expand Down Expand Up @@ -71,28 +72,31 @@ def doPassiveScan(self, baseRequestResponse):
# This is, because the insertionPoint idea doesn't work well
# for this test.
scan_issues = []

if not self.isGet(baseRequestResponse.getRequest()):
baseRequestResponse = self.switchMethod(baseRequestResponse)
if (not self.isScannableRequest(baseRequestResponse) or
if ((not (self.isScannableRequest(baseRequestResponse)) and
self.hasScriptContent(baseRequestResponse)) or
not self.isScript(baseRequestResponse) or
self.isProtected(baseRequestResponse)):
return None
newRequestResponse = self.sendUnauthenticatedRequest(baseRequestResponse)
issue = self.compareResponses(newRequestResponse, baseRequestResponse)
if not issue:
return None
# If response is script, check if script is dynamic
if self.isScript(newRequestResponse):
# sleep, in case this is a generically time stamped script
sleep(1)
secondRequestResponse = self.sendUnauthenticatedRequest(baseRequestResponse)
isDynamic = self.compareResponses(secondRequestResponse, newRequestResponse)
if isDynamic:
issue = self.reportDynamicOnly(newRequestResponse, baseRequestResponse,
secondRequestResponse)
scan_issues.append(issue)
return scan_issues
if((not (self.isScannableRequest(newRequestResponse)) and
self.hasScriptContent(newRequestResponse)) or
self.isScannableRequest(newRequestResponse)):
issue = self.compareResponses(newRequestResponse, baseRequestResponse)
if not issue:
return None
# If response is script, check if script is dynamic
if self.isScript(newRequestResponse):
# sleep, in case this is a generically time stamped script
sleep(1)
secondRequestResponse = self.sendUnauthenticatedRequest(baseRequestResponse)
isDynamic = self.compareResponses(secondRequestResponse, newRequestResponse)
if isDynamic:
issue = self.reportDynamicOnly(newRequestResponse, baseRequestResponse,
secondRequestResponse)
scan_issues.append(issue)
return scan_issues

def sendUnauthenticatedRequest(self, requestResponse):
"""
Expand Down Expand Up @@ -341,6 +345,26 @@ def consolidateDuplicateIssues(self, existingIssue, newIssue):
else:
return 0

def hasScriptContent(self,requestResponse):
"""
Checks if the response of the request contains the script content
"""
nResponse = requestResponse.getResponse()
nResponseInfo = self._helpers.analyzeResponse(nResponse)
nBodyOffset = nResponseInfo.getBodyOffset()
nBody = nResponse.tostring()[nBodyOffset:]
first_char = nBody[0:1]
if(first_char in "[" or first_char in "{"):
return "first_char"
matchvar = re.match( r'(.*)\s*(var|let|const) ([a-zA-Z])+\s*=(.*)|(.*)\s*(window.) ([a-zA-Z])+\s*=(.*)', nBody,re.M|re.I)
matchfunction=re.match( r'(.*)\s*function\((.*)\)(.*)', nBody,re.M|re.I)

if matchvar:
return matchvar
if matchfunction:
return matchfunction
else:
return None

class ScanIssue(IScanIssue):

Expand Down