Skip to content

Commit b910592

Browse files
committed
add sample module
1 parent ce01e04 commit b910592

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
2+
## [v0.2.0] - 06/26/2024
3+
### Added
4+
- `sample` module to retrive table data without manual SQL query
5+
6+
27
## [v0.1.4] - 02/03/2024
38
### Fixed
49
- Issue [#9](https://github.com/Tw1sm/PySQLRecon/issues/9)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pysqlrecon"
3-
version = "0.1.4"
3+
version = "0.2.0"
44
description = "Offensive MSSQL Python toolkit"
55
authors = ["Matt Creel <[email protected]>"]
66
readme = "README.md"

pysqlrecon/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.4'
1+
__version__ = '0.2.0'

pysqlrecon/modules/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
links, query, rows, search, smb, tables, users, whoami, \
33
enablexp, disablexp, xpcmd, enablerpc, disablerpc, enableole,\
44
disableole, enableclr, disableclr, olecmd, agentstatus, agentcmd, \
5-
clr, adsi
5+
clr, adsi, sample
66

77
__all__ = [
88
checkrpc,
@@ -13,6 +13,7 @@
1313
links,
1414
query,
1515
rows,
16+
sample,
1617
search,
1718
smb,
1819
tables,

pysqlrecon/modules/sample.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import typer
2+
3+
from pysqlrecon.logger import logger
4+
from pysqlrecon.lib import PySqlRecon
5+
6+
app = typer.Typer()
7+
COMMAND_NAME = "sample"
8+
HELP = "[bright_black][NORM][/] Query a sample of table data [I,L]"
9+
LINK_COMPATIBLE = True
10+
IMPERSONATE_COMPATIBLE = True
11+
12+
13+
@app.callback(invoke_without_command=True, no_args_is_help=True)
14+
def main(
15+
ctx : typer.Context,
16+
table : str = typer.Option(..., '--table', help='Table name'),
17+
count : int = typer.Option(5, '--count', help='Number of rows to return')):
18+
19+
pysqlrecon: PySqlRecon = ctx.obj['pysqlrecon']
20+
use_basic_tables = ctx.obj['basic_tables']
21+
22+
# verify opts are compatible with module before connecting
23+
if not PySqlRecon.validate_opts(
24+
LINK_COMPATIBLE,
25+
IMPERSONATE_COMPATIBLE,
26+
pysqlrecon.link,
27+
pysqlrecon.impersonate
28+
):
29+
exit()
30+
31+
pysqlrecon.connect()
32+
33+
if pysqlrecon.link is not None:
34+
logger.info(f"Sampling data from '{table}' in '{pysqlrecon.db}' on {pysqlrecon.link} via {pysqlrecon.target}")
35+
else:
36+
logger.info(f"Sampling data from '{table}' in '{pysqlrecon.db}' on {pysqlrecon.target}")
37+
38+
query = f"use {pysqlrecon.db}; SELECT TOP {count} * FROM {table};"
39+
pysqlrecon.query_handler(query, use_rpc_query=True)
40+
pysqlrecon.print_results(use_basic_tables)
41+
42+
pysqlrecon.disconnect()

0 commit comments

Comments
 (0)