| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d07881b commit f1ab887
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,11 +59,11 @@ def main(): | |||
| 59 | 59 | cmdLineOptions.update(cmdLineParser().__dict__) | |
| 60 | 60 | init(cmdLineOptions) | |
| 61 | 61 | ||
| 62 | - if hasattr(conf, "ipc_database"): | ||
| 62 | + if hasattr(conf, "api"): | ||
| 63 | 63 | # Overwrite system standard output and standard error to write | |
| 64 | - # to a temporary I/O database | ||
| 65 | - sys.stdout = StdDbOut(type_="stdout") | ||
| 66 | - sys.stderr = StdDbOut(type_="stderr") | ||
| 64 | + # to an IPC database | ||
| 65 | + sys.stdout = StdDbOut(conf.taskid, messagetype="stdout") | ||
| 66 | + sys.stderr = StdDbOut(conf.taskid, messagetype="stderr") | ||
| 67 | 67 | ||
| 68 | 68 | banner() | |
| 69 | 69 | ||
@@ -122,10 +122,10 @@ def main(): | |||
| 122 | 122 | except KeyboardInterrupt: | |
| 123 | 123 | pass | |
| 124 | 124 | ||
| 125 | - if hasattr(conf, "ipc_database"): | ||
| 125 | + if hasattr(conf, "api"): | ||
| 126 | 126 | try: | |
| 127 | - conf.ipc_database_cursor.close() | ||
| 128 | - conf.ipc_database_connection.close() | ||
| 127 | + conf.database_cursor.close() | ||
| 128 | + conf.database_connection.close() | ||
| 129 | 129 | except KeyboardInterrupt: | |
| 130 | 130 | pass | |
| 131 | 131 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -742,7 +742,7 @@ def setColor(message, bold=False): | |||
| 742 | 742 | ||
| 743 | 743 | return retVal | |
| 744 | 744 | ||
| 745 | - def dataToStdout(data, forceOutput=False, bold=False): | ||
| 745 | + def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=None): | ||
| 746 | 746 | """ | |
| 747 | 747 | Writes text to the stdout (console) stream | |
| 748 | 748 | """ | |
@@ -754,8 +754,15 @@ def dataToStdout(data, forceOutput=False, bold=False): | |||
| 754 | 754 | if kb.get("multiThreadMode"): | |
| 755 | 755 | logging._acquireLock() | |
| 756 | 756 | ||
| 757 | - message = stdoutencode(data) | ||
| 758 | - sys.stdout.write(setColor(message, bold)) | ||
| 757 | + if isinstance(data, basestring): | ||
| 758 | + message = stdoutencode(data) | ||
| 759 | + else: | ||
| 760 | + message = data | ||
| 761 | + | ||
| 762 | + if content_type is not None and status is not None: | ||
| 763 | + sys.stdout.write(message, status=status, content_type=content_type) | ||
| 764 | + else: | ||
| 765 | + sys.stdout.write(setColor(message, bold)) | ||
| 759 | 766 | ||
| 760 | 767 | try: | |
| 761 | 768 | sys.stdout.flush() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,3 +104,6 @@ def stdoutencode(data): | |||
| 104 | 104 | ||
| 105 | 105 | def jsonize(data): | |
| 106 | 106 | return json.dumps(data, sort_keys=False, indent=4) | |
| 107 | + | ||
| 108 | + def dejsonize(data): | ||
| 109 | + return json.loads(data) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,8 @@ | |||
| 26 | 26 | from lib.core.data import kb | |
| 27 | 27 | from lib.core.data import logger | |
| 28 | 28 | from lib.core.dicts import DUMP_REPLACEMENTS | |
| 29 | + from lib.core.enums import API_CONTENT_STATUS | ||
| 30 | + from lib.core.enums import API_CONTENT_TYPE | ||
| 29 | 31 | from lib.core.enums import DBMS | |
| 30 | 32 | from lib.core.enums import DUMP_FORMAT | |
| 31 | 33 | from lib.core.exception import SqlmapGenericException | |
@@ -52,8 +54,13 @@ def __init__(self): | |||
| 52 | 54 | self._outputFP = None | |
| 53 | 55 | self._lock = threading.Lock() | |
| 54 | 56 | ||
| 55 | - def _write(self, data, newline=True, console=True): | ||
| 57 | + def _write(self, data, newline=True, console=True, content_type=None): | ||
| 58 | + if hasattr(conf, "api"): | ||
| 59 | + dataToStdout(data, content_type=content_type, status=API_CONTENT_STATUS.COMPLETE) | ||
| 60 | + return | ||
| 61 | + | ||
| 56 | 62 | text = "%s%s" % (data, "\n" if newline else " ") | |
| 63 | + | ||
| 57 | 64 | if console: | |
| 58 | 65 | dataToStdout(text) | |
| 59 | 66 | ||
@@ -81,7 +88,7 @@ def getOutputFile(self): | |||
| 81 | 88 | def singleString(self, data): | |
| 82 | 89 | self._write(data) | |
| 83 | 90 | ||
| 84 | - def string(self, header, data, sort=True): | ||
| 91 | + def string(self, header, data, content_type=None, sort=True): | ||
| 85 | 92 | kb.stickyLevel = None | |
| 86 | 93 | ||
| 87 | 94 | if isListLike(data): | |
@@ -92,25 +99,33 @@ def string(self, header, data, sort=True): | |||
| 92 | 99 | if _ and _[-1] == '\n': | |
| 93 | 100 | _ = _[:-1] | |
| 94 | 101 | ||
| 95 | - if "\n" in _: | ||
| 102 | + if hasattr(conf, "api"): | ||
| 103 | + self._write(data, content_type=content_type) | ||
| 104 | + elif "\n" in _: | ||
| 96 | 105 | self._write("%s:\n---\n%s\n---" % (header, _)) | |
| 97 | 106 | else: | |
| 98 | 107 | self._write("%s: %s" % (header, ("'%s'" % _) if isinstance(data, basestring) else _)) | |
| 108 | + elif hasattr(conf, "api"): | ||
| 109 | + self._write(data, content_type=content_type) | ||
| 99 | 110 | else: | |
| 100 | 111 | self._write("%s:\tNone" % header) | |
| 101 | 112 | ||
| 102 | - def lister(self, header, elements, sort=True): | ||
| 103 | - if elements: | ||
| 104 | - self._write("%s [%d]:" % (header, len(elements))) | ||
| 105 | - | ||
| 106 | - if sort: | ||
| 113 | + def lister(self, header, elements, content_type=None, sort=True): | ||
| 114 | + if elements and sort: | ||
| 107 | 115 | try: | |
| 108 | 116 | elements = set(elements) | |
| 109 | 117 | elements = list(elements) | |
| 110 | 118 | elements.sort(key=lambda x: x.lower() if isinstance(x, basestring) else x) | |
| 111 | 119 | except: | |
| 112 | 120 | pass | |
| 113 | 121 | ||
| 122 | + if hasattr(conf, "api"): | ||
| 123 | + self._write(elements, content_type=content_type) | ||
| 124 | + return | ||
| 125 | + | ||
| 126 | + if elements: | ||
| 127 | + self._write("%s [%d]:" % (header, len(elements))) | ||
| 128 | + | ||
| 114 | 129 | for element in elements: | |
| 115 | 130 | if isinstance(element, basestring): | |
| 116 | 131 | self._write("[*] %s" % element) | |
@@ -121,29 +136,29 @@ def lister(self, header, elements, sort=True): | |||
| 121 | 136 | self._write("") | |
| 122 | 137 | ||
| 123 | 138 | def banner(self, data): | |
| 124 | - self.string("banner", data) | ||
| 139 | + self.string("banner", data, content_type=API_CONTENT_TYPE.BANNER) | ||
| 125 | 140 | ||
| 126 | 141 | def currentUser(self, data): | |
| 127 | - self.string("current user", data) | ||
| 142 | + self.string("current user", data, content_type=API_CONTENT_TYPE.CURRENT_USER) | ||
| 128 | 143 | ||
| 129 | 144 | def currentDb(self, data): | |
| 130 | 145 | if Backend.isDbms(DBMS.MAXDB): | |
| 131 | - self.string("current database (no practical usage on %s)" % Backend.getIdentifiedDbms(), data) | ||
| 146 | + self.string("current database (no practical usage on %s)" % Backend.getIdentifiedDbms(), data, content_type=API_CONTENT_TYPE.CURRENT_DB) | ||
| 132 | 147 | elif Backend.isDbms(DBMS.ORACLE): | |
| 133 | - self.string("current schema (equivalent to database on %s)" % Backend.getIdentifiedDbms(), data) | ||
| 148 | + self.string("current schema (equivalent to database on %s)" % Backend.getIdentifiedDbms(), data, content_type=API_CONTENT_TYPE.CURRENT_DB) | ||
| 134 | 149 | else: | |
| 135 | - self.string("current database", data) | ||
| 150 | + self.string("current database", data, content_type=API_CONTENT_TYPE.CURRENT_DB) | ||
| 136 | 151 | ||
| 137 | 152 | def hostname(self, data): | |
| 138 | - self.string("hostname", data) | ||
| 153 | + self.string("hostname", data, content_type=API_CONTENT_TYPE.HOSTNAME) | ||
| 139 | 154 | ||
| 140 | 155 | def dba(self, data): | |
| 141 | - self.string("current user is DBA", data) | ||
| 156 | + self.string("current user is DBA", data, content_type=API_CONTENT_TYPE.IS_DBA) | ||
| 142 | 157 | ||
| 143 | 158 | def users(self, users): | |
| 144 | - self.lister("database management system users", users) | ||
| 159 | + self.lister("database management system users", users, content_type=API_CONTENT_TYPE.USERS) | ||
| 145 | 160 | ||
| 146 | - def userSettings(self, header, userSettings, subHeader): | ||
| 161 | + def userSettings(self, header, userSettings, subHeader, content_type=None): | ||
| 147 | 162 | self._areAdmins = set() | |
| 148 | 163 | ||
| 149 | 164 | if userSettings: | |
@@ -179,9 +194,9 @@ def userSettings(self, header, userSettings, subHeader): | |||
| 179 | 194 | self.singleString("") | |
| 180 | 195 | ||
| 181 | 196 | def dbs(self, dbs): | |
| 182 | - self.lister("available databases", dbs) | ||
| 197 | + self.lister("available databases", dbs, content_type=API_CONTENT_TYPE.DBS) | ||
| 183 | 198 | ||
| 184 | - def dbTables(self, dbTables): | ||
| 199 | + def dbTables(self, dbTables, content_type=API_CONTENT_TYPE.TABLES): | ||
| 185 | 200 | if isinstance(dbTables, dict) and len(dbTables) > 0: | |
| 186 | 201 | maxlength = 0 | |
| 187 | 202 | ||
@@ -219,7 +234,7 @@ def dbTables(self, dbTables): | |||
| 219 | 234 | else: | |
| 220 | 235 | self.string("tables", dbTables) | |
| 221 | 236 | ||
| 222 | - def dbTableColumns(self, tableColumns): | ||
| 237 | + def dbTableColumns(self, tableColumns, content_type=API_CONTENT_TYPE.COLUMNS): | ||
| 223 | 238 | if isinstance(tableColumns, dict) and len(tableColumns) > 0: | |
| 224 | 239 | for db, tables in tableColumns.items(): | |
| 225 | 240 | if not db: | |
@@ -286,7 +301,7 @@ def dbTableColumns(self, tableColumns): | |||
| 286 | 301 | else: | |
| 287 | 302 | self._write("+%s+\n" % lines1) | |
| 288 | 303 | ||
| 289 | - def dbTablesCount(self, dbTables): | ||
| 304 | + def dbTablesCount(self, dbTables, content_type=API_CONTENT_TYPE.COUNT): | ||
| 290 | 305 | if isinstance(dbTables, dict) and len(dbTables) > 0: | |
| 291 | 306 | maxlength1 = len("Table") | |
| 292 | 307 | maxlength2 = len("Entries") | |
@@ -328,7 +343,7 @@ def dbTablesCount(self, dbTables): | |||
| 328 | 343 | else: | |
| 329 | 344 | logger.error("unable to retrieve the number of entries for any table") | |
| 330 | 345 | ||
| 331 | - def dbTableValues(self, tableValues): | ||
| 346 | + def dbTableValues(self, tableValues, content_type=API_CONTENT_TYPE.DUMP_TABLE): | ||
| 332 | 347 | replication = None | |
| 333 | 348 | rtable = None | |
| 334 | 349 | dumpFP = None | |
@@ -534,7 +549,7 @@ def dbTableValues(self, tableValues): | |||
| 534 | 549 | dumpFP.close() | |
| 535 | 550 | logger.info("table '%s.%s' dumped to %s file '%s'" % (db, table, conf.dumpFormat, dumpFileName)) | |
| 536 | 551 | ||
| 537 | - def dbColumns(self, dbColumnsDict, colConsider, dbs): | ||
| 552 | + def dbColumns(self, dbColumnsDict, colConsider, dbs, content_type=API_CONTENT_TYPE.COLUMNS): | ||
| 538 | 553 | for column in dbColumnsDict.keys(): | |
| 539 | 554 | if colConsider == "1": | |
| 540 | 555 | colConsiderStr = "s like '" + column + "' were" | |
@@ -565,13 +580,13 @@ def dbColumns(self, dbColumnsDict, colConsider, dbs): | |||
| 565 | 580 | self.dbTableColumns(_) | |
| 566 | 581 | ||
| 567 | 582 | def query(self, query, queryRes): | |
| 568 | - self.string(query, queryRes) | ||
| 583 | + self.string(query, queryRes, content_type=API_CONTENT_TYPE.SQL_QUERY) | ||
| 569 | 584 | ||
| 570 | 585 | def rFile(self, fileData): | |
| 571 | - self.lister("files saved to", fileData, sort=False) | ||
| 586 | + self.lister("files saved to", fileData, sort=False, content_type=API_CONTENT_TYPE.FILE_READ) | ||
| 572 | 587 | ||
| 573 | - def registerValue(self, registerData): | ||
| 574 | - self.string("Registry key value data", registerData, sort=False) | ||
| 588 | + def registerValue(self): | ||
| 589 | + self.string("Registry key value data", registerData, registerData, content_type=API_CONTENT_TYPE.REG_READ, sort=False) | ||
| 575 | 590 | ||
| 576 | 591 | # object to manage how to print the retrieved queries output to | |
| 577 | 592 | # standard output and sessions file | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -243,3 +243,33 @@ class WEB_API: | |||
| 243 | 243 | ASP = "asp" | |
| 244 | 244 | ASPX = "aspx" | |
| 245 | 245 | JSP = "jsp" | |
| 246 | + | ||
| 247 | + class API_CONTENT_TYPE: | ||
| 248 | + TECHNIQUES = 0 | ||
| 249 | + BANNER = 1 | ||
| 250 | + CURRENT_USER = 2 | ||
| 251 | + CURRENT_DB = 3 | ||
| 252 | + HOSTNAME = 4 | ||
| 253 | + IS_DBA = 5 | ||
| 254 | + USERS = 6 | ||
| 255 | + PASSWORDS = 7 | ||
| 256 | + PRIVILEGES = 8 | ||
| 257 | + ROLES = 9 | ||
| 258 | + DBS = 10 | ||
| 259 | + TABLES = 11 | ||
| 260 | + COLUMNS = 12 | ||
| 261 | + SCHEMA = 13 | ||
| 262 | + COUNT = 14 | ||
| 263 | + DUMP_TABLE = 15 | ||
| 264 | + SEARCH = 16 | ||
| 265 | + SQL_QUERY = 17 | ||
| 266 | + COMMON_TABLES = 18 | ||
| 267 | + COMMON_COLUMNS = 19 | ||
| 268 | + FILE_READ = 20 | ||
| 269 | + FILE_WRITE = 21 | ||
| 270 | + OS_CMD = 22 | ||
| 271 | + REG_READ = 23 | ||
| 272 | + | ||
| 273 | + class API_CONTENT_STATUS: | ||
| 274 | + IN_PROGRESS = 0 | ||
| 275 | + COMPLETE = 1 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments