Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6712f4d

Browse files
committed
some refactoring and one less request for aspx maintanance during --os-shell
1 parent 253eafb commit 6712f4d

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

lib/core/common.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,19 +1424,19 @@ def goGoodSamaritan(prevValue, originalCharset):
14241424
else:
14251425
return None, None, None, originalCharset
14261426

1427-
def getCompiledRegex(regex, *args):
1427+
def getCompiledRegex(regex, flags=0):
14281428
"""
14291429
Returns compiled regular expression and stores it in cache for further
14301430
usage
14311431
>>> getCompiledRegex('test') # doctest: +ELLIPSIS
14321432
<_sre.SRE_Pattern object at...
14331433
"""
14341434

1435-
if (regex, args) in kb.cache.regex:
1436-
return kb.cache.regex[(regex, args)]
1435+
if (regex, flags) in kb.cache.regex:
1436+
return kb.cache.regex[(regex, flags)]
14371437
else:
1438-
retVal = re.compile(regex, *args)
1439-
kb.cache.regex[(regex, args)] = retVal
1438+
retVal = re.compile(regex, flags)
1439+
kb.cache.regex[(regex, flags)] = retVal
14401440
return retVal
14411441

14421442
def getPartRun():
@@ -1628,11 +1628,11 @@ def getPublicTypeMembers(type_):
16281628

16291629
return retVal
16301630

1631-
def extractRegexResult(regex, content):
1631+
def extractRegexResult(regex, content, flags=0):
16321632
retVal = None
16331633

16341634
if regex and content and '?P<result>' in regex:
1635-
match = re.search(regex, content)
1635+
match = re.search(regex, content, flags)
16361636
if match:
16371637
retVal = match.group("result")
16381638

lib/takeover/web.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ def __webFileStreamUpload(self, stream, destFileName, directory):
8585
}
8686

8787
if self.webApi == "aspx":
88-
page = Request.getPage(url=self.webStagerUrl, content=True, raise404=False)
89-
multipartParams['__EVENTVALIDATION'] = extractRegexResult(r"__EVENTVALIDATION[^>]+value=\"(?P<result>[^\"]+)\"", page[0])
90-
multipartParams['__VIEWSTATE'] = extractRegexResult(r"__VIEWSTATE[^>]+value=\"(?P<result>[^\"]+)\"", page[0])
88+
multipartParams['__EVENTVALIDATION'] = kb.data.__EVENTVALIDATION
89+
multipartParams['__VIEWSTATE'] = kb.data.__VIEWSTATE
9190

9291
page = Request.getPage(url=self.webStagerUrl, multipart=multipartParams, raise404=False)
9392

@@ -212,6 +211,10 @@ def webInit(self):
212211
logger.warn(warnMsg)
213212
continue
214213

214+
elif self.webApi == "aspx":
215+
kb.data.__EVENTVALIDATION = extractRegexResult(r"__EVENTVALIDATION[^>]+value=\"(?P<result>[^\"]+)\"", uplPage, re.I)
216+
kb.data.__VIEWSTATE = extractRegexResult(r"__VIEWSTATE[^>]+value=\"(?P<result>[^\"]+)\"", uplPage, re.I)
217+
215218
infoMsg = "the file stager has been successfully uploaded "
216219
infoMsg += "on '%s' ('%s')" % (directory, self.webStagerUrl)
217220
logger.info(infoMsg)

0 commit comments

Comments
 (0)