我的编程空间,编程开发者的网络收藏夹
学习永远不晚

python怎么查网站漏洞

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

python怎么查网站漏洞

python怎么查网站漏洞

python查网站漏洞的方法:

使用Python脚本实现Web漏洞扫描工具,代码如下:

#!-*-coding:UTF-8-*-

import optparse, random, re, string, urllib, urllib2,difflib,itertools,httplib

NAME = "Scanner for RXSS and SQLI"

AUTHOR = "Lishuze"

PREFIXES = (" ", ") ", "' ", "') ", "\"")

SUFFIXES = ("", "-- -", "#")

BOOLEAN_TESTS = ("AND %d=%d", "OR NOT (%d=%d)")

TAMPER_SQL_CHAR_POOL = ('(', ')', '\'', '"''"')

TAMPER_XSS_CHAR_POOL = ('\'', '"', '>', '<', ';')

GET, POST = "GET", "POST"

COOKIE, UA, REFERER = "Cookie", "User-Agent", "Referer"

TEXT, HTTPCODE, TITLE, HTML = xrange(4)

_headers = {}

USER_AGENTS = (

"Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0",

"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",

"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_7_0; en-US) AppleWebKit/534.21 (KHTML, like Gecko) Chrome/11.0.678.0 Safari/534.21",

)

XSS_PATTERNS = (

(r"","\"\", inside the comment", None),

(r"(?s)","\"\", enclosed by ',"'', enclosed by ","\"\", enclosed by |"),

(r"<[^>]*'[^>']*%(chars)s[^>']*'[^>]*>", "\"<.'.xss.'.>\", inside the tag, inside single-quotes", r"(?s)|"),

(r'<[^>]*"[^>"]*%(chars)s[^>"]*"[^>]*>', "'<.\".xss.\".>', inside the tag, inside double-quotes", r"(?s)|"),

(r"<[^>]*%(chars)s[^>]*>", "\"<.xss.>\", inside the tag, outside of quotes", r"(?s)|")

)

DBMS_ERRORS = {

"MySQL": (r"SQL syntax.*MySQL", r"Warning.*mysql_.*", r"valid MySQL result", r"MySqlClient\."),

"Microsoft SQL Server": (r"Driver.* SQL[\-\_\ ]*Server", r"OLE DB.* SQL Server", r"(\W|\A)SQL Server.*Driver", r"Warning.*mssql_.*", r"(\W|\A)SQL Server.*[0-9a-fA-F]{8}", r"(?s)Exception.*\WSystem\.Data\.SqlClient\.", r"(?s)Exception.*\WRoadhouse\.Cms\."),

"Microsoft Access": (r"Microsoft Access Driver", r"JET Database Engine", r"Access Database Engine"),

"Oracle": (r"ORA-[0-9][0-9][0-9][0-9]", r"Oracle error", r"Oracle.*Driver", r"Warning.*\Woci_.*", r"Warning.*\Wora_.*")

}

def _retrieve_content_xss(url, data=None):

surl=""

for i in xrange(len(url)):

if i > url.find('?'):

surl+=surl.join(url[i]).replace(' ',"%20")

else:

surl+=surl.join(url[i])

try:

req = urllib2.Request(surl, data, _headers)

retval = urllib2.urlopen(req, timeout=30).read()

except Exception, ex:

retval = getattr(ex, "message", "")

return retval or ""

def _retrieve_content_sql(url, data=None):

retval = {HTTPCODE: httplib.OK}

surl=""

for i in xrange(len(url)):

if i > url.find('?'):

surl+=surl.join(url[i]).replace(' ',"%20")

else:

surl+=surl.join(url[i])

try:

req = urllib2.Request(surl, data, _headers)

retval[HTML] = urllib2.urlopen(req, timeout=30).read()

except Exception, ex:

retval[HTTPCODE] = getattr(ex, "code", None)

retval[HTML] = getattr(ex, "message", "")

match = re.search(r"(?P<result>[^<]+)", retval[HTML], re.I)

retval[TITLE] = match.group("result") if match else None

retval[TEXT] = re.sub(r"(?si)|||<[^>]+>|\s+", " ", retval[HTML])

return retval

def scan_page_xss(url, data=None):

print "Start scanning RXSS:\n"

retval, usable = False, False

url = re.sub(r"=(&|\Z)", "=1\g<1>", url) if url else url

data=re.sub(r"=(&|\Z)", "=1\g<1>", data) if data else data

try:

for phase in (GET, POST):

current = url if phase is GET else (data or "")

for match in re.finditer(r"((\A|[?&])(?P[\w]+)=)(?P[^&]+)", current):

found, usable = False, True

print "Scanning %s parameter '%s'" % (phase, match.group("parameter"))

prefix = ("".join(random.sample(string.ascii_lowercase, 5)))

suffix = ("".join(random.sample(string.ascii_lowercase, 5)))

if not found:

tampered = current.replace(match.group(0), "%s%s" % (match.group(0), urllib.quote("%s%s%s%s" % ("'", prefix, "".join(random.sample(TAMPER_XSS_CHAR_POOL, len(TAMPER_XSS_CHAR_POOL))), suffix))))

content = _retrieve_content_xss(tampered, data) if phase is GET else _retrieve_content_xss(url, tampered)

for sample in re.finditer("%s([^ ]+?)%s" % (prefix, suffix), content, re.I):

#print sample.group()

for regex, info, content_removal_regex in XSS_PATTERNS:

context = re.search(regex % {"chars": re.escape(sample.group(0))}, re.sub(content_removal_regex or "", "", content), re.I)

if context and not found and sample.group(1).strip():

print "!!!%s parameter '%s' appears to be XSS vulnerable (%s)" % (phase, match.group("parameter"), info)

found = retval = True

if not usable:

print " (x) no usable GET/POST parameters found"

except KeyboardInterrupt:

print "\r (x) Ctrl-C pressed"

return retval

def scan_page_sql(url, data=None):

print "Start scanning SQLI:\n"

retval, usable = False, False

url = re.sub(r"=(&|\Z)", "=1\g<1>", url) if url else url

data=re.sub(r"=(&|\Z)", "=1\g<1>", data) if data else data

try:

for phase in (GET, POST):

current = url if phase is GET else (data or "")

for match in re.finditer(r"((\A|[?&])(?P\w+)=)(?P[^&]+)", current):

vulnerable, usable = False, True

original=None

print "Scanning %s parameter '%s'" % (phase, match.group("parameter"))

tampered = current.replace(match.group(0), "%s%s" % (match.group(0), urllib.quote("".join(random.sample(TAMPER_SQL_CHAR_POOL, len(TAMPER_SQL_CHAR_POOL))))))

content = _retrieve_content_sql(tampered, data) if phase is GET else _retrieve_content_sql(url, tampered)

for (dbms, regex) in ((dbms, regex) for dbms in DBMS_ERRORS for regex in DBMS_ERRORS[dbms]):

if not vulnerable and re.search(regex, content[HTML], re.I):

print "!!!%s parameter '%s' could be error SQLi vulnerable (%s)" % (phase, match.group("parameter"), dbms)

retval = vulnerable = True

vulnerable = False

original = original or (_retrieve_content_sql(current, data) if phase is GET else _retrieve_content_sql(url, current))

for prefix,boolean,suffix in itertools.product(PREFIXES,BOOLEAN_TESTS,SUFFIXES):

if not vulnerable:

template = "%s%s%s" % (prefix,boolean, suffix)

payloads = dict((_, current.replace(match.group(0), "%s%s" % (match.group(0), urllib.quote(template % (1 if _ else 2, 1), safe='%')))) for _ in (True, False))

contents = dict((_, _retrieve_content_sql(payloads[_], data) if phase is GET else _retrieve_content_sql(url, payloads[_])) for _ in (False, True))

if all(_[HTTPCODE] for _ in (original, contents[True], contents[False])) and (any(original[_] == contents[True][_] != contents[False][_] for _ in (HTTPCODE, TITLE))):

vulnerable = True

else:

ratios = dict((_, difflib.SequenceMatcher(None, original[TEXT], contents[_][TEXT]).quick_ratio()) for _ in (True, False))

vulnerable = all(ratios.values()) and ratios[True] > 0.95 and ratios[False] < 0.95

if vulnerable:

print "!!!%s parameter '%s' could be error Blind SQLi vulnerable" % (phase, match.group("parameter"))

retval = True

if not usable:

print " (x) no usable GET/POST parameters found"

except KeyboardInterrupt:

print "\r (x) Ctrl-C pressed"

return retval

def init_options(proxy=None, cookie=None, ua=None, referer=None):

global _headers

_headers = dict(filter(lambda _: _[1], ((COOKIE, cookie), (UA, ua or NAME), (REFERER, referer))))

urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler({'http': proxy})) if proxy else None)

if __name__ == "__main__":

print "----------------------------------------------------------------------------------"

print "%s\nBy:%s" % (NAME, AUTHOR)

print "----------------------------------------------------------------------------------"

parser = optparse.OptionParser()

parser.add_option("--url", dest="url", help="Target URL")

parser.add_option("--data", dest="data", help="POST data")

parser.add_option("--cookie", dest="cookie", help="HTTP Cookie header value")

parser.add_option("--user-agent", dest="ua", help="HTTP User-Agent header value")

parser.add_option("--random-agent", dest="randomAgent", action="store_true", help="Use randomly selected HTTP User-Agent header value")

parser.add_option("--referer", dest="referer", help="HTTP Referer header value")

parser.add_option("--proxy", dest="proxy", help="HTTP proxy address")

options, _ = parser.parse_args()

if options.url:

init_options(options.proxy, options.cookie, options.ua if not options.randomAgent else random.choice(USER_AGENTS), options.referer)

result_xss= scan_page_xss(options.url if options.url.startswith("http") else "http://%s" % options.url, options.data)

print "\nScan results: %s vulnerabilities found" % ("possible" if result_xss else "no")

print "----------------------------------------------------------------------------------"

result_sql = scan_page_sql(options.url if options.url.startswith("http") else "http://%s" % options.url, options.data)

print "\nScan results: %s vulnerabilities found" % ("possible" if result_sql else "no")

print "----------------------------------------------------------------------------------"

else:

parser.print_help()

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

python怎么查网站漏洞

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

网站被攻击怎么办 如何查找网站漏洞攻击源

很多企业网站被攻击,导致网站打开跳转到别的网站,尤其一些等非法网站上去,甚至有些网站被攻击的打不开,客户无法访问首页,给客户造成了很大的经济损失,很多客户找到我们SINE安全公司寻求防止网站被攻击的解决方案,针对这一情况,我们安全部门的技术
2023-06-03

网站被黑该怎么修复漏洞

近日wordpress被爆出高危的网站漏洞,该漏洞可以伪造代码进行远程代码执行,获取管理员的session以及获取cookies值,漏洞的产生是在于wordpress默认开启的文章评论功能,该功能在对评论的参数并没有进行详细的安全过滤与拦截
2023-06-03

网站漏洞修复之Metinfo 文件上传漏洞

Metinfo CMS系统被爆出网站存在漏洞,可上传任意文件到网站根目录下,从而使攻击者可以轻易的获取网站的webshell权限,对网站进行篡改与攻击,目前该网站漏洞影响范围是Metinfo 6.2.0最新版本,以及以前的所有Metinfo
2023-06-03

编程热搜

  • Python 学习之路 - Python
    一、安装Python34Windows在Python官网(https://www.python.org/downloads/)下载安装包并安装。Python的默认安装路径是:C:\Python34配置环境变量:【右键计算机】--》【属性】-
    Python 学习之路 - Python
  • chatgpt的中文全称是什么
    chatgpt的中文全称是生成型预训练变换模型。ChatGPT是什么ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类完成一系列
    chatgpt的中文全称是什么
  • C/C++中extern函数使用详解
  • C/C++可变参数的使用
    可变参数的使用方法远远不止以下几种,不过在C,C++中使用可变参数时要小心,在使用printf()等函数时传入的参数个数一定不能比前面的格式化字符串中的’%’符号个数少,否则会产生访问越界,运气不好的话还会导致程序崩溃
    C/C++可变参数的使用
  • css样式文件该放在哪里
  • php中数组下标必须是连续的吗
  • Python 3 教程
    Python 3 教程 Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。 Python
    Python 3 教程
  • Python pip包管理
    一、前言    在Python中, 安装第三方模块是通过 setuptools 这个工具完成的。 Python有两个封装了 setuptools的包管理工具: easy_install  和  pip , 目前官方推荐使用 pip。    
    Python pip包管理
  • ubuntu如何重新编译内核
  • 改善Java代码之慎用java动态编译

目录