3333import urllib2
3434import urlparse
3535
36- from ConfigParser import DEFAULTSECT
37- from ConfigParser import RawConfigParser
38-
3936from lib .core .common import getConsoleWidth
4037from lib .core .common import getFileType
4138from lib .core .common import normalizePath
4542from lib .core .common import paths
4643from lib .core .common import randomRange
4744from lib .core .common import sanitizeStr
45+ from lib .core .common import UnicodeRawConfigParser
4846from lib .core .data import conf
4947from lib .core .data import kb
5048from lib .core .data import logger
7775proxyHandler = urllib2 .BaseHandler ()
7876redirectHandler = SmartRedirectHandler ()
7977
80-
81- class UnicodeRawConfigParser (RawConfigParser ):
82- def write (self , fp ):
83- """Write an .ini-format representation of the configuration state."""
84- if self ._defaults :
85- fp .write ("[%s]\n " % DEFAULTSECT )
86- for (key , value ) in self ._defaults .items ():
87- fp .write ("%s = %s\n " % (key , unicode (value ).replace ('\n ' , '\n \t ' )))
88- fp .write ("\n " )
89- for section in self ._sections :
90- fp .write ("[%s]\n " % section )
91- for (key , value ) in self ._sections [section ].items ():
92- if key != "__name__" :
93- if value is None :
94- fp .write ("%s\n " % (key ))
95- else :
96- fp .write ("%s = %s\n " %
97- (key , unicode (value ).replace ('\n ' , '\n \t ' )))
98- fp .write ("\n " )
99-
10078def __urllib2Opener ():
10179 """
10280 This function creates the urllib2 OpenerDirector.
@@ -118,7 +96,7 @@ def __urllib2Opener():
11896 urllib2 .install_opener (opener )
11997
12098def __feedTargetsDict (reqFile , addedTargetUrls ):
121- fp = codecs .open (reqFile , "r " , conf .dataEncoding )
99+ fp = codecs .open (reqFile , "rb " , conf .dataEncoding )
122100
123101 fread = fp .read ()
124102 fread = fread .replace ("\r " , "" )
@@ -856,6 +834,13 @@ def __cleanupOptions():
856834 debugMsg = "cleaning up configuration parameters"
857835 logger .debug (debugMsg )
858836
837+ width = getConsoleWidth ()
838+
839+ if conf .eta :
840+ conf .progressWidth = width - 26
841+ else :
842+ conf .progressWidth = width - 46
843+
859844 if conf .testParameter :
860845 conf .testParameter = conf .testParameter .replace (" " , "" )
861846 conf .testParameter = conf .testParameter .split ("," )
@@ -932,13 +917,6 @@ def __setConfAttributes():
932917 conf .threadException = False
933918 conf .wFileType = None
934919
935- width = getConsoleWidth ()
936-
937- if conf .eta :
938- conf .progressWidth = width - 26
939- else :
940- conf .progressWidth = width - 46
941-
942920def __setKnowledgeBaseAttributes ():
943921 """
944922 This function set some needed attributes into the knowledge base
@@ -989,7 +967,6 @@ def __setKnowledgeBaseAttributes():
989967 kb .unionNegative = False
990968 kb .unionFalseCond = False
991969
992-
993970def __saveCmdline ():
994971 """
995972 Saves the command line options on a sqlmap configuration INI file
@@ -1002,7 +979,7 @@ def __saveCmdline():
1002979 debugMsg = "saving command line options on a sqlmap configuration INI file"
1003980 logger .debug (debugMsg )
1004981
1005- config = UnicodeRawConfigParser ()
982+ config = UnicodeRawConfigParser ()
1006983 userOpts = {}
1007984
1008985 for family in optDict .keys ():
@@ -1019,6 +996,9 @@ def __saveCmdline():
1019996 optionData .sort ()
1020997
1021998 for option , value , datatype in optionData :
999+ if isinstance (datatype , (list , tuple , set )):
1000+ datatype = datatype [0 ]
1001+
10221002 if value is None :
10231003 if datatype == "boolean" :
10241004 value = "False"
@@ -1037,10 +1017,8 @@ def __saveCmdline():
10371017
10381018 config .set (family , option , value )
10391019
1040- print 11111
1041- confFP = codecs .open (paths .SQLMAP_CONFIG , "wb" , "UTF8" )
1020+ confFP = codecs .open (paths .SQLMAP_CONFIG , "wb" , conf .dataEncoding )
10421021 config .write (confFP )
1043- print 22222
10441022
10451023 infoMsg = "saved command line options on '%s' configuration file" % paths .SQLMAP_CONFIG
10461024 logger .info (infoMsg )
@@ -1112,11 +1090,11 @@ def init(inputOptions=advancedDict()):
11121090 based upon command line and configuration file options.
11131091 """
11141092
1093+ __setConfAttributes ()
1094+ __setKnowledgeBaseAttributes ()
11151095 __mergeOptions (inputOptions )
11161096 __setVerbosity ()
11171097 __saveCmdline ()
1118- __setConfAttributes ()
1119- __setKnowledgeBaseAttributes ()
11201098 __cleanupOptions ()
11211099 __basicOptionValidation ()
11221100 __setRequestFromFile ()
0 commit comments