MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / _setSafeVisit

Function _setSafeVisit

lib/core/option.py:1225–1282  ·  view source on GitHub ↗

Check and set the safe visit options.

()

Source from the content-addressed store, hash-verified

1223 _urllib.request.install_opener(opener)
1224
1225def _setSafeVisit():
1226 """
1227 Check and set the safe visit options.
1228 """
1229 if not any((conf.safeUrl, conf.safeReqFile)):
1230 return
1231
1232 if conf.safeReqFile:
1233 checkFile(conf.safeReqFile)
1234
1235 raw = readCachedFileContent(conf.safeReqFile)
1236 match = re.search(r"\A([A-Z]+) ([^ ]+) HTTP/[0-9.]+\Z", raw.split('\n')[0].strip())
1237
1238 if match:
1239 kb.safeReq.method = match.group(1)
1240 kb.safeReq.url = match.group(2)
1241 kb.safeReq.headers = {}
1242
1243 for line in raw.split('\n')[1:]:
1244 line = line.strip()
1245 if line and ':' in line:
1246 key, value = line.split(':', 1)
1247 value = value.strip()
1248 kb.safeReq.headers[key] = value
1249 if key.upper() == HTTP_HEADER.HOST.upper():
1250 if not value.startswith("http"):
1251 scheme = "http"
1252 if value.endswith(":443"):
1253 scheme = "https"
1254 value = "%s://%s" % (scheme, value)
1255 kb.safeReq.url = _urllib.parse.urljoin(value, kb.safeReq.url)
1256 else:
1257 break
1258
1259 post = None
1260
1261 if '\r\n\r\n' in raw:
1262 post = raw[raw.find('\r\n\r\n') + 4:]
1263 elif '\n\n' in raw:
1264 post = raw[raw.find('\n\n') + 2:]
1265
1266 if post and post.strip():
1267 kb.safeReq.post = post
1268 else:
1269 kb.safeReq.post = None
1270 else:
1271 errMsg = "invalid format of a safe request file"
1272 raise SqlmapSyntaxException(errMsg)
1273 else:
1274 if not re.search(r"(?i)\Ahttp[s]*://", conf.safeUrl):
1275 if ":443/" in conf.safeUrl:
1276 conf.safeUrl = "https://%s" % conf.safeUrl
1277 else:
1278 conf.safeUrl = "http://%s" % conf.safeUrl
1279
1280 if (conf.safeFreq or 0) <= 0:
1281 errMsg = "please provide a valid value (>0) for safe frequency ('--safe-freq') while using safe visit features"
1282 raise SqlmapSyntaxException(errMsg)

Callers 1

initFunction · 0.85

Calls 5

checkFileFunction · 0.90
readCachedFileContentFunction · 0.90
findMethod · 0.80
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…