通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率]

admin 2021年4月23日04:31:23评论42 views字数 2580阅读8分36秒阅读模式

本文作者:mzfuzzMs08067安全实验室成员


前言:

python的特性这里不过多细说,简单来说可以让我们很快完成任务。

日常工作中,难免我们会重复工作,这里就需要我们去写好一些相关的模块,然后等需要用的时候,直接调用自己写的包即可,这样可以节省自己大量的时间用来研究漏洞或者刷朋友圈!

下面我大概举3个模块来说明


网页下载函数:


"""htmldown 此函数功能是 输入url连接,然后保存到本地进行备份。多用在有翻页的后台进行后台备份,输入翻页url,参数等进行批量down备份url: 访问urlfilename: 保存网页信息的本地目录head: 请求header"""

def htmldown(url,filename,head): for i in range(0,4): try: res=requests.get(url,header=head,timeout=5) with open(filename,'a+') as f: f.write(res.text) print(f"{url} successful!!!") return except Exception as e: print(e) pass


通常我们渗透下站点,需要下载解析一些站点信息,大部分信息都是存在页数得,这里就可以通过此函数来进行下载,填写url,header头,下载文件保存位置即可如果遇到post请求,可以使用下面函数即可!


"""htmldown_post 此函数功能是 输入url连接,然后保存到本地进行备份。多用在有翻页的后台进行后台备份,输入翻页url,参数等进行批量down备份[请求方式为post请求]参数:url: 访问urlfilename: 保存网页信息的本地目录head: 请求headerdata1: post请求的参数"""def htmldown_post(url,filename,head,data1):    for i in range(0,4):        try:

res=requests.post(url,header=head,data=data1,timeout=5) with open(filename,'a+') as f: f.write(res.text) print(f"{url}+'t'+{data1} successful!!!") return except Exception as e: print(e) pass



header头解析:


上文中得header是必不可缺得,因为场景往往是访问后台,需要cookie认证.

为了更方便快捷,直接复制burp抓得包赋值给变量,然后解析成字典格式即可相关代码见下:


# head="""# GET /userInfo/getUserBasicInfo HTTP/1.1# Host: admin.ceshi123.com# Connection: close# Accept: */*# User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36# X-Requested-With: XMLHttpRequest# Accept-Encoding: gzip, deflate# Accept-Language: zh-CN,zh;q=0.9,en;q=0.8# Cookie: phpsession=3478173981273981ceshi# """
def ls_header(str_headers: str) -> dict: if not str_headers: return {} items = str_headers.splitlines() headers = {} for item in items: item_str = item.strip() if not item_str: continue if item_str.startswith(':'): continue i = item_str.find(':') headers[item_str[:i]] = item_str[i + 1:].strip() return headers


xlsx文件生成和读取:


execl文件处理是我们常见得,我们再处理文件得时候,不管需要解析,还是要过滤,都需要读取,我们对网站后台解析后得数据也需要execl进行输出。

这里我们就可以写个函数,用来读取xlsx文件,返回数组列表。也可以将数组列表生成xlsx文件代码见下:


"""read_xlsx()读取xlsx文件 结果返回列表"""
def read_xlsx(f): try: file1=f xls_list=[] table = load_workbook(f) sheetname=table.sheetnames for shee in sheetname: data=table[shee]
rows=data.rows for i in rows: a=[] for x in i: # print(x.value) a.append(str.lower(str(x.value))) xls_list.append(a)

return xls_list except Exception as e: print(e) pass
"""write_xlsx 此函数用来生成xlsx文件传入参数必须是列表,多个函数组合调用来生成excel文件"""
def write_xlsx(datas,fi): try: wb=Workbook()        ws=wb.active
for i in datas: ws.append(i) wb.save(fi) print(f"save file as {fi}!!! ") except Exception as e: print(e)


结尾#

相关代码github:

https://github.com/shinyxiaoxia/mzfuzz

这种每个人得使用都不一样,所以可以参考下这种方法,一点点去模块化自己频繁的操作。


之后需要什么操作,只需要import mzfuzz即可。






扫描下方二维码加入星球学习

加入后会邀请你进入内部微信群,内部微信群永久有效!

通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率] 通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率]

通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率] 通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率] 通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率]

目前30000+人已关注加入我们

通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率]

本文始发于微信公众号(Ms08067安全实验室):通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率]

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年4月23日04:31:23
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   通过编写python函数来一步步打造属于自己得渗透模块[提升工作效率]http://cn-sec.com/archives/292863.html

发表评论

匿名网友 填写信息