|
2 | 2 | from typing import Any |
3 | 3 | from rich.table import Table |
4 | 4 |
|
| 5 | +from pysqlrecon.lib.exceptions import DuplicateAssemblyError |
5 | 6 | from pysqlrecon.logger import logger, console |
6 | 7 | from pysqlrecon.lib.sqlagent import SqlAgentMixin |
7 | 8 | from pysqlrecon.lib.clr import ClrMixin |
|
11 | 12 |
|
12 | 13 | class PySqlRecon(SqlAgentMixin, ClrMixin, ModuleMixin, QueryMixin): |
13 | 14 |
|
| 15 | + # https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors-6000-to-6999?view=sql-server-ver16 |
| 16 | + DUPLICATE_ASM_ERROR = 6285 |
| 17 | + |
| 18 | + |
14 | 19 | def __init__(self, target, domain, username, password, port, link, impersonate, |
15 | 20 | db, hashes, aesKey, kerberos, no_pass, dc_ip, windows_auth) -> None: |
16 | 21 |
|
@@ -205,9 +210,15 @@ def print_replies(self) -> None: |
205 | 210 | for keys in list(self.ms_sql.replies.keys()): |
206 | 211 | for i, key in enumerate(self.ms_sql.replies[keys]): |
207 | 212 | if key['TokenType'] == tds.TDS_ERROR_TOKEN: |
| 213 | + error_num = key['Number'] |
208 | 214 | error = "(%s): Line %d: %s" % (key['ServerName'].decode('utf-16le'), key['LineNumber'], key['MsgText'].decode('utf-16le')) |
209 | 215 | self.lastError = tds.SQLErrorException("ERROR: Line %d: %s" % (key['LineNumber'], key['MsgText'].decode('utf-16le'))) |
210 | 216 | logger.error(error) |
| 217 | + |
| 218 | + # handle duplicate assembly error |
| 219 | + if error_num == PySqlRecon.DUPLICATE_ASM_ERROR: |
| 220 | + raise DuplicateAssemblyError(error) |
| 221 | + |
211 | 222 | exit() |
212 | 223 |
|
213 | 224 | elif key['TokenType'] == tds.TDS_INFO_TOKEN: |
|
0 commit comments