1111import socket
1212import time
1313
14- from difflib import SequenceMatcher
15-
1614from lib .core .agent import agent
1715from lib .core .common import beep
1816from lib .core .common import extractRegexResult
17+ from lib .core .common import findDynamicContent
1918from lib .core .common import getCompiledRegex
2019from lib .core .common import getInjectionTests
2120from lib .core .common import getUnicode
4746from lib .core .exception import sqlmapUserQuitException
4847from lib .core .session import setString
4948from lib .core .session import setRegexp
50- from lib .core .settings import DYNAMICITY_MARK_LENGTH
5149from lib .core .settings import UPPER_RATIO_BOUND
5250from lib .core .unescaper import unescaper
5351from lib .request .connect import Connect as Request
@@ -494,8 +492,7 @@ def checkDynParam(place, parameter, value):
494492
495493def checkDynamicContent (firstPage , secondPage ):
496494 """
497- This function checks if the provided pages have dynamic content. If they
498- are dynamic, proper markings will be made.
495+ This function checks for the dynamic content in the provided pages
499496 """
500497
501498 if kb .nullConnection :
@@ -510,47 +507,29 @@ def checkDynamicContent(firstPage, secondPage):
510507 logger .debug (debugMsg )
511508 return
512509
513- infoMsg = "searching for dynamic content"
514- logger .info (infoMsg )
515-
516- blocks = SequenceMatcher (None , firstPage , secondPage ).get_matching_blocks ()
517- kb .dynamicMarkings = []
510+ conf .seqMatcher .set_seq1 (firstPage )
511+ conf .seqMatcher .set_seq2 (secondPage )
518512
519- # Removing too small matching blocks
520- i = 0
521- while i < len (blocks ):
522- block = blocks [i ]
523- (_ , _ , length ) = block
513+ # In case of an intolerable difference turn on dynamicity removal engine
514+ if conf .seqMatcher .quick_ratio () <= UPPER_RATIO_BOUND :
515+ findDynamicContent (firstPage , secondPage )
524516
525- if length <= DYNAMICITY_MARK_LENGTH :
526- blocks .remove (block )
527-
528- else :
529- i += 1
517+ count = 0
518+ while not Request .queryPage ():
519+ count += 1
530520
531- # Making of dynamic markings based on prefix/suffix principle
532- if len (blocks ) > 0 :
533- blocks .insert (0 , None )
534- blocks .append (None )
521+ if count > conf .retries :
522+ errMsg = "target url is too dynamic. unable to continue. "
523+ errMsg += "consider using other switches (e.g. "
524+ errMsg += "--longest-common, --string, --text-only, etc.)"
525+ raise sqlmapSiteTooDynamic , errMsg
535526
536- for i in xrange (len (blocks ) - 1 ):
537- prefix = firstPage [blocks [i ][0 ]:blocks [i ][0 ] + blocks [i ][2 ]] if blocks [i ] else None
538- suffix = firstPage [blocks [i + 1 ][0 ]:blocks [i + 1 ][0 ] + blocks [i + 1 ][2 ]] if blocks [i + 1 ] else None
539-
540- if prefix is None and blocks [i + 1 ][0 ] == 0 :
541- continue
542-
543- if suffix is None and (blocks [i ][0 ] + blocks [i ][2 ] >= len (firstPage )):
544- continue
527+ warnMsg = "target url is heavily dynamic"
528+ warnMsg += ", sqlmap is going to retry the request"
529+ logger .critical (warnMsg )
545530
546- prefix = trimAlphaNum (prefix )
547- suffix = trimAlphaNum (suffix )
548-
549- kb .dynamicMarkings .append ((re .escape (prefix [- DYNAMICITY_MARK_LENGTH / 2 :]) if prefix else None , re .escape (suffix [:DYNAMICITY_MARK_LENGTH / 2 ]) if suffix else None ))
550-
551- if len (kb .dynamicMarkings ) > 0 :
552- infoMsg = "dynamic content marked for removal (%d region%s)" % (len (kb .dynamicMarkings ), 's' if len (kb .dynamicMarkings ) > 1 else '' )
553- logger .info (infoMsg )
531+ secondPage , _ = Request .queryPage (content = True )
532+ findDynamicContent (firstPage , secondPage )
554533
555534def checkStability ():
556535 """
@@ -637,29 +616,7 @@ def checkStability():
637616 errMsg = "Empty value supplied"
638617 raise sqlmapNoneDataException , errMsg
639618 else :
640- conf .seqMatcher .set_seq1 (firstPage )
641- conf .seqMatcher .set_seq2 (secondPage )
642-
643- # In case of an intolerable difference turn on dynamicity removal engine
644- if conf .seqMatcher .quick_ratio () <= UPPER_RATIO_BOUND :
645- checkDynamicContent (firstPage , secondPage )
646-
647- count = 0
648- while not Request .queryPage ():
649- count += 1
650-
651- if count > conf .retries :
652- errMsg = "target url is too dynamic. unable to continue. "
653- errMsg += "consider using other switches (e.g. "
654- errMsg += "--longest-common, --string, --text-only, etc.)"
655- raise sqlmapSiteTooDynamic , errMsg
656-
657- warnMsg = "target url is heavily dynamic"
658- warnMsg += ", sqlmap is going to retry the request"
659- logger .critical (warnMsg )
660-
661- secondPage , _ = Request .queryPage (content = True )
662- checkDynamicContent (firstPage , secondPage )
619+ checkDynamicContent (firstPage , secondPage )
663620
664621 return kb .pageStable
665622
0 commit comments